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

匆匆过客 提交于 2019-11-26 22:55:07

问题


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

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 onCreate of my activity :

@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

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.

I am using HTC WildFire-S, android ver 2.3.5


回答1:


In your manifest xml, at application level put this:

<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.




回答2:


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

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

    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:theme declarations, 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.

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




回答3:


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:

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



回答4:


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);
}



回答5:


This will fix your problem

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

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


来源:https://stackoverflow.com/questions/10086371/androidtheme-androidstyle-theme-notitlebar-fullscreen-works-on-application

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!