简体   繁体   English

如何隐藏/删除android中的标题栏

[英]How to hide/remove the title bar in android

In my code I write: 在我的代码中,我写道:

    this.requestWindowFeature(Window.FEATURE_NO_TITLE);
    this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
    this.setContentView(R.layout.activity_main);

I've written all of it before the setContentView() call is made but it doesn't work. 我在调用setContentView()之前编写了所有内容,但它不起作用。

I've already used the theme in android studio to remove the title bar and set the app to fullscreen but nothing changed. 我已经在android studio中使用了主题来删除标题栏并将应用程序设置为全屏但没有任何改变。

How can I remove or hide the title bar that shows by default, when developing an android app? 在开发Android应用程序时,如何删除或隐藏默认显示的标题栏?

转到值并选择styles.xml将AppTheme更改为

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

To inherit from a predefined style definition 从预定义的样式定义继承

1. Create a new style definition in your styles.xml file and make it a child of Theme.AppCompat.Light.NoActionBar . 1.在styles.xml文件中创建一个新的样式定义,并使其成为Theme.AppCompat.Light.NoActionBar的子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. Add the new style definition to your application tag in the AndroidManifest.xml file 2.将新样式定义添加到AndroidManifest.xml文件中的应用程序标记

<application
    ...
    android:theme="@style/AppTheme">

To specify the individual properties 指定各个属性

Add the following properties to a new or existing style definition in the styles.xml file and ensure the style definition has been referenced in the AndroidManifest.xml file, as above: 将以下属性添加到styles.xml文件中的新样式或现有样式定义,并确保已在AndroidManifest.xml文件中引用样式定义,如上所述:

<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM