Full Screen Theme for AppCompat

2019-01-01 07:57发布

问题:

I would like to know how can I apply full screen theme ( no title bar + no actionbar ) to an activity. I am using AppCompat library from support package v7.

I\'ve tried to applied android:theme=\"@android:style/Theme.NoTitleBar.Fullscreen\" to my specific activity but it crashed. I think it\'s because my application theme is like this.

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

I also have tried this

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

which only hides title bar but not the action bar. My current workaround is that hiding the actionbar with

getSupportActionBar().hide();

回答1:

When you use Theme.AppCompat in your application you can use FullScreenTheme by adding the code below to styles.

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

and also mention in your manifest file.

<activity
   android:name=\".activities.FullViewActivity\"
   android:theme=\"@style/Theme.AppCompat.Light.NoActionBar.FullScreen\" 
/>


回答2:

Based on the answer by @nebyan, I found that the action bar is still not hiding.

The following code works for me:

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

and of course dont forgot to edit your AndroidManifest file.

<activity
    android:name=\"YOUR_ACTIVITY_NAME\"
    android:theme=\"@style/AppFullScreenTheme\" 
/>


回答3:

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

Using the above xml in style.xml, you will be able to hide the title as well as action bar.



回答4:

Issues arise among before and after versions of Android 4.0 (API level 14)..

from here https://developer.android.com/training/system-ui/status.html I created my own solution..

@SuppressLint(\"NewApi\")
@Override
protected void onResume()
{
    super.onResume();

    if (Build.VERSION.SDK_INT < 16)
    {
        // Hide the status bar
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
        // Hide the action bar
        getSupportActionBar().hide();
    }
    else
    {
        // Hide the status bar
        getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_FULLSCREEN);
        / Hide the action bar
        getActionBar().hide();
    }
}

I write this code in onResume() method because if you exit from your app and then you reopen it, the action bar remains active! (and so this fix the problem)

I hope it was helpful ;)



回答5:

Your \"workaround\" (hiding the actionBar yourself) is the normal way. But google recommands to always hide the ActionBar when the TitleBar is hidden. Have a look here: https://developer.android.com/training/system-ui/status.html



回答6:

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    //to remove \"information bar\" above the action bar
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);
    //to remove the action bar (title bar)
    getSupportActionBar().hide();
}


回答7:

You can follow below step:-

AndoridMenifest.xml

<activity
            android:name=\".ui.FullImageActivity\"
            android:label=\"@string/title_activity_main\"
            android:screenOrientation=\"landscape\"
            android:theme=\"@style/DialogTheme\">
        </activity>

Style.xml

<style name=\"DialogTheme\" parent=\"android:Theme.Dialog\">

    <item name=\"android:layout_width\">fill_parent</item>
    <item name=\"android:layout_height\">fill_parent</item>

   <!-- No backgrounds, titles or window float -->
    <item name=\"android:windowNoTitle\">false</item>
    <item name=\"android:windowFullscreen\">true</item>
    <item name=\"android:windowIsFloating\">false</item>
</style>

FullImageActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().setLayout(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
    setContentView(R.layout.image_view);
     }

I hope it will help..Thanks!!



回答8:

It should be parent=\"@style/Theme.AppCompat.Light.NoActionBar\"

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


回答9:

requestWindowFeature(Window.FEATURE_NO_TITLE);


回答10:

To remove title bar in AppCompat:

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        supportRequestWindowFeature(Window.FEATURE_NO_TITLE);
        super.onCreate(savedInstanceState);
    }


回答11:

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



回答12:

just this ?

<style name=\"Theme.AppCompat.Light.NoActionBar.FullScreen\">
    <item name=\"android:windowFullscreen\">true</item>
</style>


回答13:

This theme only works after API 21(included). And make both the StatusBar and NavigationBar transparent.

<style name=\"TransparentAppTheme\" parent=\"Theme.AppCompat.Light.DarkActionBar\">
  <item name=\"windowActionBar\">false</item>
  <item name=\"windowNoTitle\">true</item>
  <item name=\"android:statusBarColor\">@android:color/transparent</item>
  <item name=\"android:windowBackground\">@android:color/transparent</item>
  <item name=\"android:navigationBarColor\">@android:color/transparent</item>
  <item name=\"android:windowIsTranslucent\">true</item>
  <item name=\"android:windowContentOverlay\">@null</item>
</style>


回答14:

Simply at this guys to your Style:

<style name=\"AppTheme\" parent=\"@style/Theme.AppCompat.Light\">
<item name=\"windowNoTitle\">true</item>
<item name=\"windowActionBar\">false</item>
<item name=\"android:windowFullscreen\">true</item>
<item name=\"android:windowContentOverlay\">@null</item> </style>


回答15:

To hide both status bar and action bar and make your activity full-screen use the following code in your activity\'s onResume() or onWindowFocusChanged() method:

@Override
protected void onResume() {
    super.onResume();
    View decorView = getWindow().getDecorView();
    decorView.setSystemUiVisibility(
            View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
            | View.SYSTEM_UI_FLAG_LAYOUT_STABLE
            | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
            | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
            | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
            | View.SYSTEM_UI_FLAG_FULLSCREEN);
}

You can find more Information in the following links:

  • https://developer.android.com/training/system-ui/immersive#EnableFullscreen
  • Full Screen without navigation & status bars
  • How to hide the soft-key bar on Android phone?

Note: Using the xml solutions provide in this thread I could only hide the status bar but not the navigation bar.