skip to Main Content

I Have set an image in my ActivityMain.xml, and there is no action bar theme is used. I want
The photo that I set in the background this image will show the background of the status bar.

Please Look at this image,

2

Answers


  1. What I assume from your question is that you want to achieve a Full Screen Activity with your blue color as background of status bar for that you can set your status bar to transparent and your screen to stretch out to full screen

    window?.decorView?.systemUiVisibility = (View.SYSTEM_UI_FLAG_LAYOUT_STABLE
            or View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN)
    window.statusBarColor = Color.TRANSPARENT
    
    Login or Signup to reply.
  2. You need can achieve that by following steps:

    1. Declare one theme in your styles.xml
    <style name="FullScreenTheme" parent="Theme.MaterialComponents.DayNight.NoActionBar">
            <item name="colorPrimary">@color/background</item>
            <item name="colorPrimaryDark">@color/background</item>
            <item name="colorAccent">@color/primary</item>
            <item name="colorControlActivated">@color/primary</item>
            <item name="android:windowLightStatusBar" tools:targetApi="m">false</item>
            <item name="android:windowTranslucentNavigation" tools:targetApi="kitkat">true</item>
            <item name="android:statusBarColor" tools:targetApi="lollipop">@android:color/transparent</item>
    </style>
    

    Note: android:windowTranslucentNavigation is important attribute here.

    1. Now in your activity xml’s parent layout, add android:fitsSystemWindows="true" to fill your UI in full screen.

    2. in your Activity class, inside onCreate Method, need to set NO_LIMIT flag like this;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN);
    
        setContentView(R.layout.your_xml);
    
    }
    
    1. Now set this theme your class from android manifest.
    <activity
        android:name=".YourActivity"
        android:theme="@style/FullScreenTheme" />
    

    Hope, this will helps you.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search