在我的代码中,我写道:
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
this.setContentView(R.layout.activity_main);
我在拨打setContentView()
电话之前已经写了所有这些内容,但它不起作用。
我已经在 android 工作室中使用了主题来删除标题栏并将应用程序设置为全屏,但没有任何变化。
在开发 android 应用程序时,如何删除或隐藏默认显示的标题栏?
从预定义的样式定义继承
1. 在styles.xml
文件中创建一个新的样式定义,并使其成为Theme.AppCompat.Light.NoActionBar
的子项。
For example:
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
2. 将新的样式定义添加到AndroidManifest.xml
文件中的应用程序标记
<application
...
android:theme="@style/AppTheme">
指定各个属性
将以下属性添加到styles.xml
文件中的新样式定义或现有样式定义,并确保已在AndroidManifest.xml
文件中引用样式定义,如上所述:
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
setContentView(...) 之前在 onCreate() 方法中添加以下代码
requestWindowFeature(Window.FEATURE_NO_TITLE);
getSupportActionBar().hide();
getSupportActionBar() 方法用于检索 ActionBar 类的实例。 调用 ActionBar 类的 hide() 方法将隐藏标题栏。
转到值并选择样式.xml将应用主题更改为
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">