Full Screen Theme for AppCompat
Asked Answered
O

15

331

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();
Ovida answered 18/12, 2013 at 8:43 Comment(2)
<h3>Answer With Output Screenshot</h3> Here you can checkFatuous
<h3>Answer With Output Screenshot</h3> Here you can checkFatuous
S
891

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" 
/>
Schlessinger answered 18/8, 2014 at 14:1 Comment(8)
The parent style should be "Theme.AppCompat.Light.NoActionBar"Happiness
Actually, it's enough to add this to the style xml file: <item name="android:windowFullscreen">true</item>. The action bar (title bar) visibility can be separately controlled using .hide/.show methods at runtime.Logy
FEATURE_NO_TITLE was not being honored. Dunno the difference, but I finally changed my Activity to extend Activity instead of AppCompatActivity and my same code worked (thankfully I don't need AppCompat): this.requestWindowFeature(Window.FEATURE_NO_TITLE); getWindow().getDecorView().setSystemUiVisibility( View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);Veterinary
this hides status bar as well :(Fixate
I would add hideNavigation() in onResume() - without that, the navigation bar was still visible in my app (api 18+)Deviant
no need to set <item name="android:windowNoTitle">true</item> <item name="android:windowActionBar">false</item> if your theme includes .NoActionBarSwig
Is there a list anywhere of all of the Theme.AppCompat variants?Gleaning
I had to replace "android:windowNoTitle" with "windowNoTitle" for this to work.Mou
H
74

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" 
/>
Happiness answered 24/1, 2015 at 13:1 Comment(2)
@Schlessinger why your solution does not work, and this one works for me? What is the reason?Beesley
no need to set <item name="android:windowNoTitle">true</item> <item name="android:windowActionBar">false</item> if your theme includes .NoActionBarSwig
B
19
<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.

Byronbyrum answered 23/7, 2014 at 17:48 Comment(0)
V
13

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

from here 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).

Vicinage answered 22/3, 2014 at 0:0 Comment(1)
Notice that if user manually pull the status bar, it won't rehide itself. To make it worse, if soft keyboard is showing, status bar automatically shows as well and again, won't rehide.Kiersten
S
7

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

Schulein answered 18/12, 2013 at 8:50 Comment(0)
S
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);
     }
Sponsor answered 18/12, 2013 at 9:50 Comment(0)
D
7
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();
}
Dhumma answered 19/11, 2016 at 12:32 Comment(0)
T
5

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:

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

Toothed answered 11/10, 2018 at 9:35 Comment(1)
Thank you, this is the only one hiding the navigation bar! Highly recommend this answer.Pearse
R
4

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>
Reluctance answered 15/9, 2017 at 9:54 Comment(0)
B
4

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>
Barbel answered 16/2, 2018 at 7:5 Comment(1)
Only this solution actually hides the title bar and makes it completely full screen. Should be marked as the correct solution. Thanks!Pyoid
E
2
requestWindowFeature(Window.FEATURE_NO_TITLE);
Engel answered 28/1, 2014 at 12:42 Comment(0)
D
2

You can try the following :

<style name="AppTheme.NoActionBar" parent="Theme.AppCompat.Light.NoActionBar">
            <item name="android:windowFullscreen">true</item>
</style>
Descry answered 6/2, 2019 at 8:45 Comment(0)
A
1

To remove title bar in AppCompat:

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        supportRequestWindowFeature(Window.FEATURE_NO_TITLE);
        super.onCreate(savedInstanceState);
    }
Avant answered 4/8, 2016 at 20:10 Comment(0)
D
1
<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>

Dowse answered 15/5, 2017 at 12:51 Comment(1)
Please also explain code, if you provide it, it helps understanding your code and may help to gain insights for future problems.Wingate
V
0

just this ?

<style name="Theme.AppCompat.Light.NoActionBar.FullScreen">
    <item name="android:windowFullscreen">true</item>
</style>
Virgenvirgie answered 6/7, 2017 at 13:6 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.