Android - Making activity full screen with status bar on top of it

后端 未结 8 1392
北恋
北恋 2020-12-12 19:30

I want to make my activity full screen with status bar on top of it like this picture:

I have used this code in manifest inside activity

相关标签:
8条回答
  • 2020-12-12 19:48

    Put this code in your Activity onCreate this will hide the status bar

    View decorView = getWindow().getDecorView();
    // Hide the status bar.
    int uiOptions = View.SYSTEM_UI_FLAG_FULLSCREEN;
    decorView.setSystemUiVisibility(uiOptions);
    // Remember that you should never show the action bar if the
    // status bar is hidden, so hide that too if necessary.
    ActionBar actionBar = getActionBar();
    actionBar.hide();
    
    0 讨论(0)
  • 2020-12-12 19:50

    you can use this code after onCreate

       setTheme(android.R.style.Theme_Black_NoTitleBar_Fullscreen);
            getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
            if (getSupportActionBar() != null) {
                getSupportActionBar().hide();
            }
    

    your activity will be fullscrean with status bar :)

    0 讨论(0)
  • 2020-12-12 19:54

    Try Like This

     <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
            <!-- Customize your theme here. -->
            <item name="colorPrimary">@color/colorPrimary</item>
            <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
            <item name="colorAccent">@color/colorAccent</item>
            <item name="windowActionBar">false</item>
            <item name="windowNoTitle">true</item>
        </style>
    

    Hope this one will help

    0 讨论(0)
  • 2020-12-12 19:56

    I know that the guy asking the question may have found his own solution but for the people who are still looking for a solution this is a very simple solution but one thing it has a limitation till Kitkat so a condition is added

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
    
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS,
                          WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
    }
    
    0 讨论(0)
  • 2020-12-12 19:57

    @tahsinRupam answer is correct and tested on post Kitkat version.

    <item name="android:windowTranslucentStatus">true</item>
    <item name="android:windowTranslucentNavigation">true</item>
    

    If you want to use it only for a certain activity, create a style, and attach it on your manifest style like this.

    <activity
        android:name=".MainActivity"
        android:screenOrientation="portrait"
        android:theme="@style/Activity.Fullscreen.Theme" />
    
    <style name="Activity.Fullscreen.Theme" parent="MyMaterialTheme.Base">  
        <item name="android:windowTranslucentStatus">true</item>
        <item name="android:windowTranslucentNavigation">true</item>
    </style>
    

    Thumbs up on origal @tahsinRupam

    Happy codings Cheers !

    0 讨论(0)
  • 2020-12-12 20:01

    Add these to your Base Application Theme in styles.xml

    <item name="android:windowTranslucentStatus">true</item>
    <item name="android:windowTranslucentNavigation">true</item>
    

    And add following attribute to your parent layout:

    android:fitsSystemWindows="false"
    

    Hope this helps.

    0 讨论(0)
提交回复
热议问题