-1

I am trying to achieve brighter translucent status bar ,only the status bar and trying to keep navigation bar as its default.

I tried some solutions(actually non of them worked as what i want).

In this one i couldn't change translucent transparency, i am trying to get brighter one.But it is not changing.
http://blog.raffaeu.com/archive/2015/04/11/android-and-the-transparent-status-bar.aspx

The other option, i tried to use fullscreen theme and placed a gradient view same height as status(that is what i want). But in this time Layout extends behind of navigation and navigation looses its black background.I couldn't find solution for that.(making it translucent not what i want)

TLDR : i am trying to get brighter translucent status with keeping navigation as its default. Is it possible?
Edit. min SDK is 20 (sorry for bad english)

Ferhat Ergün
  • 135
  • 1
  • 10

2 Answers2

3

Yes, it is possibile.

  1. Set the translucent status

    <style name="AppThemeTranslucent" parent="Theme.AppCompat.Light.NoActionBar">
          <item name="android:windowTranslucentStatus">true</item>
          <item name="android:windowTranslucentNavigation">true</item>
    </style>
    
  2. Set a color for your status bar using:

    @TargetApi(Build.VERSION_CODES.LOLLIPOP)
    private void setTrasparentStatusBar() {
    Window window = getWindow();
        window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
    
        window.setStatusBarColor(ContextCompat.getColor(this, R.color.status_bar_color));
    
        window.setNavigationBarColor(ContextCompat.getColor(this, android.R.color.black));
    }
    
  3. Add this property to you root layout

    android:fitsSystemWindows="true"
    

And this is what I achieve with this code

sample


EDIT

I investigated about this feature, not all the view implement fitsSystemWindows so not always you can get this results.

I suggest you to read this and here a repo with a sample using a CoordinatorLayout with a negative marginTop

appersiano
  • 2,670
  • 22
  • 42
  • Navigation stays translucent, if i remove translucency of navigation, it oddly remove status bar colour to white. I think navigation translucency overrides navigation colour – Ferhat Ergün Dec 05 '17 at 08:25
  • I forgot to tell you to add fitSystemWindows attribute, check the updated answer! – appersiano Dec 05 '17 at 09:05
  • i think i have issue with my theme or layout. I need to figure out first. Thanks!! – Ferhat Ergün Dec 05 '17 at 09:35
  • i couldn't get black navigation sorry it still does same thing, either layout extends behind of navigation or status bar looses its transparency – Ferhat Ergün Dec 05 '17 at 13:35
1

I found the solution here
By adding this one into onCreate()

getWindow().getDecorView().setSystemUiVisibility(
   View.SYSTEM_UI_FLAG_LAYOUT_STABLE
    | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);  

And this adding this into your style

 <item name="android:statusBarColor">@android:color/transparent</item>
Ferhat Ergün
  • 135
  • 1
  • 10