简体   繁体   English

Android:如何删除活动标题栏?

[英]Android: How to remove the Activity Title Bar?

I am wanting to get rid of the Activity Title Bar as it is annoying to have. 我想摆脱活动标题栏,因为它很烦人。 However, I do not want to have a fullscreen activity.I have tried just adding @android:style/Theme.NoTitleBar to activity and android:theme="@android:style/Theme.NoTitleBar.Fullscreen to the manifest file, but I keep getting the error: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity . Nothing seems to help. 但是,我不想进行全屏活动。我尝试将@android:style/Theme.NoTitleBar添加到活动中,并将android:theme="@android:style/Theme.NoTitleBar.Fullscreen到清单文件中,但是我继续得到错误: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity似乎无济于事。

如果要求您使用Appcompat主题-使用appcompat主题

Theme.AppCompat.Light.NoActionBar

You can extend Activity instead of AppCompatActivity and use the following code: 您可以扩展Activity而不是AppCompatActivity并使用以下代码:

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // remove title bar
    this.requestWindowFeature(Window.FEATURE_NO_TITLE);

    // remove notification bar 
    this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_WindowManager.LayoutParams.FLAG_FULLSCREEN);

    setContentView(R.layout.activity_splash);
}

It's possible to set flags to an activty window: 可以将标志设置到活动窗口:

For example you can achieve your propose writing this on the onCreate method of your activity. 例如,您可以实现在活动的onCreate方法上编写此提案的建议。

getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
    WindowManager.LayoutParams.FLAG_FULLSCREEN);

Do this in onCreate onCreate执行此操作

    //Remove title bar
    this.requestWindowFeature(Window.FEATURE_NO_TITLE);

In your style.xml 在你的style.xml中

    <style name="Theme.AppCompat.Light.NoActionBar" parent="@style/Theme.AppCompat.Light">
         <item name="android:windowNoTitle">true</item>
         <item name="windowActionBar">false</item>
    </style>

Hope it helps 希望能帮助到你

Simplest way to go: 最简单的方法:

getActionBar().hide();

put it in your onCreate method and you'll never see the Action Bar. 将其放在onCreate方法中,您将永远不会看到操作栏。

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

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