使用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>