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

后端 未结 5 1518
清歌不尽
清歌不尽 2020-12-05 11:37

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

I have added in the Manifest :



        
相关标签:
5条回答
  • 2020-12-05 11:45

    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);
    }
    
    0 讨论(0)
  • 2020-12-05 11:52

    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

    0 讨论(0)
  • 2020-12-05 11:54

    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.

    0 讨论(0)
  • 2020-12-05 12:05

    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"
    
    0 讨论(0)
  • 2020-12-05 12:11

    This will fix your problem

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

    <application
        ...
        android:theme="@style/Theme.AppCompat.NoActionBar">
        ...
    </application>
    
    0 讨论(0)
提交回复
热议问题