0
点赞
收藏
分享

微信扫一扫

Android使用Toolbar自定义顶部导航栏

爱情锦囊 2022-05-01 阅读 76

使用toolbar自定义导航栏 

首先需要引入依赖:

在xml文件写入

     <androidx.appcompat.widget.Toolbar
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/toolbar"
        android:background="@color/teal_200">
    </androidx.appcompat.widget.Toolbar>

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">

 

这样就可以了

提示:

文字居中:

    <androidx.appcompat.widget.Toolbar
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/toolbar"
        android:background="@color/teal_200">
        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:textSize="30dp"
            android:text="文字居中"/>
    </androidx.appcompat.widget.Toolbar>

 

举报

相关推荐

0 条评论