android:theme="@android:style/Theme.NoTitleBar.Fullscreen" 适用于应用程序级别,但不适用于活动级别。有什么线索吗?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10086371/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 02:26:55  来源:igfitidea点击:

android:theme="@android:style/Theme.NoTitleBar.Fullscreen" works on Application level but not at the activity level. Any clue?

androidandroid-activityandroid-manifeststatusbarandroid-theme

提问by Vikas Singh

I need to make one of my activities called MyNoStatusBarActivity.javaa full-screen activity.

我需要将我的一项活动称为MyNoStatusBarActivity.java全屏活动。

I have added in the Manifest :

我在清单中添加了:

<activity
    android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
    android:name=".MyNoStatusBarActivity"
    android:noHistory="true"
    android:label="@string/app_name"
    android:configChanges="touchscreen|keyboard|keyboardHidden|navigation|orientation">
    ...
</activity>

And in the onCreateof my activity :

onCreate我的活动中:

@Override
public void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);

    requestWindowFeature(Window.FEATURE_NO_TITLE);

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

Doing all this just hides the TITLE bar and not the STATUS bar.

这样做只是隐藏了标题栏而不是状态栏。

Also if I use the manifest theme on the application level instead of my activity, it works but for all activities of my app which is not what I want. I want the no status bar only for one particular activity.

此外,如果我在应用程序级别使用清单主题而不是我的活动,它可以工作,但适用于我的应用程序的所有活动,这不是我想要的。我只想要一项特定活动的无状态栏。

Help will be really appreciated. Thnx!

帮助将不胜感激。谢谢!

P.S : I am ok is this behavior is no longer available in Honeycomb/ICS. I need this just for 2.2 and 2.3

PS:我很好,这个行为在 Honeycomb/ICS 中不再可用。我只需要 2.2 和 2.3

EDIT

编辑

Tried all the suggestions mentioned in other solutions in SO but no success yet. Theme works when applied to the application level but not on the activity level.

尝试了 SO 中其他解决方案中提到的所有建议,但尚未成功。主题适用于应用程序级别而不是活动级别。

I am using HTC WildFire-S, android ver 2.3.5

我使用的是 HTC WildFire-S,Android 版本 2.3.5

回答by Neoh

In your manifest xml, at application level put this:

在您的清单 xml 中,在应用程序级别放置:

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

and in the activity that you want to make full screen put this:

并在您想要全屏显示的活动中输入:

<activity

     android:theme="@android:style/Theme.NoTitleBar.Fullscreen" >
     ...
</activity>

Remove all the setWindowsFeature or setFlag methods in onCreate.

删除 onCreate 中的所有 setWindowsFeature 或 setFlag 方法。

回答by Sam Clewlow

I think you just need to take the android:theme="@android:style/Theme.NoTitleBar.Fullscreenout of the mainfest, stick with code only call, it's always worked for me. Which test device are you using?

我认为你只需要android:theme="@android:style/Theme.NoTitleBar.Fullscreen退出 mainfest,坚持只调用代码,它总是对我有用。您使用的是哪种测试设备?

Also make sure these calls come beforeyou call to setContentView(R.layout.xxx)like this

还要确保你打电话给setContentView(R.layout.xxx)这样的电话之前收到这些电话

    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
    setContentView(R.layout.xxx);

Check all of your code for android:themedeclarations, ie manifest and individual layouts xml files. as it sounds like declaring it at app level is working (as it's overriding any subsequent theme declarations) but there is something overriding your activity level request.

检查所有代码的android:theme声明,即清单和单独的布局 xml 文件。因为听起来在应用程序级别声明它是有效的(因为它会覆盖任何后续的主题声明),但是有一些东西会覆盖您的活动级别请求。

Try searching your whole project for "android:theme" and remove anything that you're not 100% sure you need, test it that way

尝试在整个项目中搜索“android:theme”并删除您不确定 100% 需要的任何内容,以这种方式进行测试

回答by haelsite

I put this in my activity:

我把它放在我的活动中:

requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_splash);

And in my manifest I don't modify, this is mine, without modifications:

在我的清单中我没有修改,这是我的,没有修改:

android:theme="@style/AppTheme"

In my activty xml:

在我的活动 xml 中:

android:theme="@android:style/Theme.NoTitleBar.Fullscreen"

回答by ahmedali

This will do the trick:

这将解决问题:

protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);

    requestWindowFeature(Window.FEATURE_NO_TITLE);

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

    setContentView(R.layout.activity_main);
}

回答by Juan Denis

This will fix your problem

这将解决您的问题

just change in your manifest @android:style... for @style/..

只需更改您的清单 @android:style... 为 @style/..

<application
    ...
    android:theme="@style/Theme.AppCompat.NoActionBar">
    ...
</application>