Android 如何去掉自带的 ActionBar
要去掉 Android 自带的 ActionBar,可以按照以下步骤操作:
- 在你的 Android 项目的 styles.xml 文件中定义一个主题,继承自 NoActionBar:
 
<style name='AppTheme' parent='Theme.AppCompat.Light.NoActionBar'>
</style>
- 在 AndroidManifest.xml 文件中为应用程序指定该主题:
 
<application
    android:theme='@style/AppTheme'>
</application>
这样就可以去掉 Android 自带的 ActionBar 了。如果你想要添加一个自定义的 Toolbar,可以参考以下代码:
<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/AppTheme.PopupOverlay' />
然后在你的 Activity 中设置 Toolbar 为 ActionBar:
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
原文地址: https://www.cveoy.top/t/topic/nRiW 著作权归作者所有。请勿转载和采集!