I'm try to developing an app with a navigation drawer from a template found on github.
In style.xml i have:
<style name="AppTheme" parent="Theme.AppCompat.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#ff0000</item>
<item name="colorPrimaryDark">#0000ff</item>
and the status bar in navigation drawer is ok.
When i click the button it runs this command:
getWindow().setStatusBarColor(Color.GREEN);
Now the status bar color in navigation drawer is no more translucent
How restore status bar color to translucent?
The difference is that the xml defined colors colorPrimary and colorPrimaryDark are not really used to directly set the status bar color.
Actually the statusbar is completely transparent all the time and only the underlaying View is colored. Thats why it can have another color on the left than on the right side (have a look at your second screenshot). If you now call getWindow().setStatusBarColor(..) you indeed color the statusbar directly and over-draw the color of both Views. So it needs to stay transparent!
What you really want to do, is changing the color of the View underlaying the status bar, which is done with the ScrimInsetsFrameLayout class.
Have a look at this question and this class from the library you provided
There you should find all the necessary information to change only the color of the area you want to.
In case you really just want to reset the color:
getWindow().setStatusBarColor(Color.TRANSPARENT);
Related
Guys I want to have translucent status bar with black background navigation buttons. Just like Netflix App as shown in picture. I tried really hard to find any way but I failed to achieve this. Any Idea?
Add in styles.xml in Base Application style
Change status bar color : <item name="android:statusBarColor">#color/blackColor</item>
For Translucent status bar : <item name="android:windowTranslucentStatus">true</item>
For navigation bar color : <item name="android:navigationBarColor">#color/blackColor</item>
in layout file use : android:fitsSystemWindows="true" in root layout.
I use White Action Bar and i want to use black color icons to Open Navigation drawer and more options button?
I tried using a White Action Bar but i end up getting all the icons or the buttons to be invisible in the Action bar since they are also in white color.
Kindly suggest how can i set color to the Action bar elements, as of now i want to display black icons on the Action bar with shadow.
Voila! I have found the answer.
Just Replace the code in styles.xml
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Light" />
Note: When u use a Light theme, it is understood that you will use only light colours in the action bar and therefore the colour of the text and icons are made dark(black).
Thank me later!
I'm having the hardest time changing the color beneath the transparent status bar color. The transparency is fine when the drawer is open, but the color beneath is wrong. Different fragments are going to have different action bar colors.
fitsSystemWindow has no effect.
Changing the status bar color just makes it solid.
If I set a color with a lower alpha, it just mixes with the green (Primary Color Dark).
What is happening: (Color underneath is green)
What I want is exactly like what is happening in the play store:
The following should do what you want:
First make sure that your app theme in v21/style.xml has
<item name="android:windowTranslucentStatus">true</item>
Use mDrawerLayout.setStatusBarBackgroundColor() for changing the background color of statusBar on fragment change instead of setStatusBarColor().
Make sure your coordinatorLayout doesn't contain the property android:fitsSystemWindows.
I'm trying to set my Action Bar color to transparent, so it will have the same color as the background and will also blend in with the gradient background.
I tried doing something like this:
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">#android:color/transparent</item>
</style>
When I run my app, it launches, loads the screen for one second (all rendered correctly, action bar is transparent), then crashes to the following exception:
java.lang.IllegalArgumentException: background can not be translucent: #0
Tracing to no relevant class of my project.
If I set the parameter to a solid color, everything works fine.
Can you help me with the problem? I couldn't find any solution.
Thanks.
Your app isn't crashing as a result of the ActionBar background being transparent, but as a result of your colorPrimary being transparent, in combination with using the MediaRouter lib.
MediaRouterThemeHelper.getControllerColor and MediaRouterThemeHelper.getButtonTextColor both make calls to ColorUtils.calculateContrast, which is where your IllegalArgumentException is coming from.
ColorUtils.calculateContrast needs a fully opaque color in order to correctly calculate contrast, just based on the formula being used and MediaRouterThemeHelper uses colorPrimary to determine how to theme the MediaRouter controller and button text color.
It looks like you're using a NoActionBar style, so I'm assuming you're using a Toolbar and just setting the background to be your colorPrimary. Instead you could just use #android:color/transparent directly and change your colorPrimary to something opaque.
My problem is easy but I need some help
I have a MainActivity, several Fragments and NavigationDrawer. I also use a Appcompat v7
NavigationDrawer is shown behind the statusbar for what I use ScrimInsetsLayout.
In styles I have colorPrimary and colorPrimaryDark(parent is Theme.Appcompat)
In main activity I use setStatusBarColor(Color.TRANSPARENT) to show Drawer in statusbar. So now I have colorPrimaryDark statusbar color and NavigationDrawer in statusbar
Now I created a new Fragment and I need to disable colorPrimaryDark color and make statusbar real transparent
As I said before, setting color to transparent makes it colorPrimaryDark with drawer shown
Setting it to any other color "hides" drawer.
Thanks
Screenshots:
The transparent translucent status bar is available from API 19, create a new values-v19 folder and a styles.xml inside it then update your BaseAppTheme like this:
<!-- Base application theme for v19. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowTranslucentNavigation">false</item>
<item name="android:windowTranslucentStatus">true</item>
</style>
But, this would make your UI use the space behind StatusBar, so I would suggest adding an extra TOP padding, of 25dp (researched and found every API uses 25dp as StatusBar height even in landscape mode), for devices > API19