I'd like to know what's the name of the part on top of the action bar (where the time is displayed alongside the battery, wifi, etc), and how can its color be changed ?
Thanks !
That's the status bar.
Just add colorPrimaryDark item to your theme in styles.xml
<item name="colorPrimaryDark">#color/primary.dark</item>
Related
I want to create my own Android app and my problem is that I can only see a charging icon in the status bar instead of battery, time, wifi etc.
Above you can see how it looks, but there is not much to see.
In styles.xml I chose this Theme:
style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar
If you need more information just ask.
I found out that my status bar was white because the colorPrimaryDark in colors.xml was white. And normally the status bar has the color of PrimaryDark.
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 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);
I want to delete the confirm button that appears on left side of CAB when my app si in selection mode. Or replace it with a back button.
I have a single selection mode, so, in contextual action bar I need only title, and a back button.
I follow android tutorial and all work fine, but now how can I remove default confirm ?
You can change the icon on the top left by changing it in the theme.
If you styles.xml, create a new theme if you don't have one already.
<style name="Theme.Custom.Light" parent="Holo.Theme.Light">
<item name="android:actionModeCloseDrawable">#drawable/ic_menu_checkmark</item>
</style>
You can put in any drawable here. Just tried it and it worked.
In my android app, in the Action Bar, next to the < image is an icon. I want to make it invisible/gone ondemand dynamically. How do I do that? The icon is actually defined as follows (this should help you realize where in the action bar I am talking about).
<style name="MyAppName.LogoTheme.LogoActionBar" parent="MyAppName.Theme.ActionBar">
<item name="android:displayOptions">showHome|homeAsUp</item>
<item name="android:icon">#drawable/my_icon</item>
I tried the following, but nothing.
this.getActionBar().setDisplayHomeAsUpEnabled(false);
this.getActionBar().setLogo(null);
this.getActionBar().setDisplayUseLogoEnabled(true);
In Java, call setDisplayShowHomeEnabled(false) and setDisplayShowTitleEnabled(false) on your ActionBar.