步骤 踩坑
- 设置主题样式,在style文件中,没有actionbar的样式
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
- 第二步 设置toolbar的布局文件
<com.google.android.material.appbar.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/Theme.NavigationDemo.AppBarOverlay">
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/Theme.NavigationDemo.PopupOverlay" />
</com.google.android.material.appbar.AppBarLayout>
- 第三步 代码使用
setSupportActionBar(binding.toolbar)
后面可以
设置Title,menu ,Logo, subTitle
