I have use toolbar in my app with style
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/holo_blue</
<item name="actionModeStyle">#style/Search.ActionMode</item>
<item name="windowActionModeOverlay">true</item>
</style>
Then I used a contextual action bar and able to change the background color.
<style name="Search.ActionMode" parent="#style/Widget.AppCompat.ActionMode">
<item name="background">#color/actionModeColor</item>
</style>
But I am unable to change the background color of popup menu.
Here is the image
And I wanted the background color of popup menu to be white. I also tried to change the theme by Widget.AppCompat.Light.ActionBar in Search.ActionMode but it does nothing.
There is an easy way to change the colors in Actionbar Use ActionBar Generator:
http://jgilfelt.github.io/android-actionbarstylegenerator/
and copy paste all file in your res folder and change your theme in Android.manifest file.
I have faced the same problem as yours. What I did is
I changed from
<!-- Base application theme. -->
<style name="Theme.Noteplus.Base.Brown" parent="Theme.AppCompat.Light.NoActionBar">
<item name="actionModeStyle">#style/Widget.ActionMode</item>
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
to
<!-- Base application theme. -->
<style name="Theme.Noteplus.Base.Brown" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="actionModeStyle">#style/Widget.ActionMode</item>
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
solve the problem. (Not exactly sure the reason behind)
(https://stackoverflow.com/a/50114013/72437)
Related
I cannot seem to get what I want no matter how much reading I do on this subject - yet what I want is quite simple.
I am applying a global style to my app based on AppCompat NoActionBar. This gives white text and I want to change it to a dark colour. Here is my styles.xml:
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorAccent">#color/colorSecondary</item>
<item name="android:textColor">#ff4400</item>
</style>
<style name="ToolBarStyle" parent="Theme.AppCompat">
<item name="android:textColorPrimary">#android:color/white</item>
<item name="android:textColorSecondary">#android:color/white</item>
<item name="actionMenuTextColor">#android:color/white</item>
<item name="android:background">#color/colorPrimary</item>
<item name="colorControlNormal">#android:color/white</item>
</style>
This is fine. The text colour is changed to a dark colour everywhere (set to red here so I can see what's happening). Unfortunately this also overrides all of the text colouring for buttons. Disabled buttons show the dark colour and there is no way to distinguish them from enabled buttons. I've tried applying styles to buttons but the textColor always overrides the disabled colour.
I'm at a bit of a loss as to how to proceed. I don't want to apply a selector on every button nor colour all the buttons individually by setting a style on each one. I want an overall global colour change - which Android seems to have made exceptionally difficult.
I eventually managed to get it to work. I had to use a selector. I provide my solution below.
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorButtonNormal">#color/colorSecondary</item>
<item name="android:textColorPrimary">#color/primary_text_color_selector</item>
<item name="android:textColorSecondary">#color/secondary_text_color_selector</item>
<item name="alertDialogTheme">#style/ThemeDialog</item>
</style>
<style name="ThemeDialog" parent="Theme.AppCompat.Light.Dialog.Alert">
<item name="android:textColorPrimary">#color/primary_text_color_selector</item>
<item name="android:background">#color/colorTertiary</item>
</style>
<style name="ToolBarStyle" parent="Theme.AppCompat">
<item name="android:textColorPrimary">#android:color/white</item>
<item name="android:textColorSecondary">#android:color/white</item>
<item name="actionMenuTextColor">#android:color/white</item>
<item name="android:background">#color/colorPrimary</item>
<item name="colorControlNormal">#android:color/white</item>
</style>
First of all, I'd like to clarify that I'm willing to change the color of the Hamburger nav menu icon itself, and not the icons within the nav menu.
I followed this tutorial: https://developer.android.com/training/implementing-navigation/nav-drawer#DrawerButton
As a result, I have a NavMenu Icon (Hamburger) within the app bar. Problem: The icon is black (the default color of the Vector drawable).
I created a new style:
<!-- Hamburger menu -->
<style name="MyDrawerArrowToggle" parent="Widget.AppCompat.DrawerArrowToggle">
<item name="color">#color/colorTextTitle</item>
</style>
I then added this style to my theme:
<style name="customTheme" parent="Theme.AppCompat.NoActionBar">
<!-- Hamburger menu -->
<item name="drawerArrowStyle">#style/MyDrawerArrowToggle</item>
</style>
Made sure this style was the one used by my app in the manifest:
<application>
android:theme="#style/customTheme"
</application>
And also applied this theme to the toolbar (just in case...)
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="#color/colorToolbarBackground"
app:theme="#style/customTheme"
app:popupTheme="#style/customTheme"
app:title="#string/app_name"
app:titleTextColor="#color/colorTextBody">
</android.support.v7.widget.Toolbar>
</FrameLayout>
Result of the operation: None of this had any effect. The hamburger icon remains desperately black.
Would any of you be able to explain to me what mistake I made and how I can change this color?
I recommend you take a look at the sample provided by Google/Android Studio.
Create a new project called test-hamburger (name optional ;-) )
Select the "Drawer" template obviously. I didn't check "Use AndroidX" but should work.
I selected MinAPI 23/Target 28.
After you have the sample app, run it and observe toolbar is green and text/tint is white.
Open values/styles.xml (not the v21 version, f**c those) :)
This is how the existing theme looks:
<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>
</style>
You need to add this line to it:
<item name="drawerArrowStyle">#style/DrawerArrowStyle</item>
And of course, define the style:
<style name="DrawerArrowStyle" parent="#style/Widget.AppCompat.DrawerArrowToggle">
<item name="spinBars">true</item>
<item name="color">#android:color/holo_red_dark</item>
</style>
All in all, your style should now look like:
<!-- Base application theme. -->
<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="drawerArrowStyle">#style/DrawerArrowStyle</item>
</style>
<style name="DrawerArrowStyle" parent="#style/Widget.AppCompat.DrawerArrowToggle">
<item name="spinBars">true</item>
<item name="color">#android:color/holo_red_dark</item>
</style>
Which, when run, looks like:
Use this as the style of your toolbar
<style name="Toolbar">
<item name="android:textColorPrimary">#color/colorAccent</item>
<item name="android:textColor">#color/colorAccent</item>
<item name="android:textColorSecondaryInverse">#color/colorAccent</item>
<item name="android:textColorSecondary">#color/colorAccent</item>
</style>
I hope it helps
I dont know why but because of some reasons my overflow button in my actionbar is transparent.Are there any reasons for that and how can I fix it ? Whats the default style for it ? I dont want to download material icons from Google because I think they should be already in it.
My AppTheme style :
<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="android:windowFullscreen">true</item>
<item name="windowActionModeOverlay">true</item>
<item name="android:actionModeBackground">#color/colorPrimary</item>
<item name="colorAccent">#color/colorPrimary</item>
I tried to change the default icon of HomeAsUpEnabled by editing my styles.xml file. But my icon did't changed. I am working on min sdk version:23. Below is my styles.xml file.
My styles.xml file
<!-- Base application theme. -->
<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>
<item name="android:homeAsUpIndicator">#drawable/back</item>
<item name="homeAsUpIndicator">#drawable/back</item>
</style>
Use the Toolbar and call toolbar.setNavigationIcon(). See more on toolbar here http://developer.android.com/reference/android/widget/Toolbar.html
How do I make the ActionBar title uppercase? Some answers suggest putting <item name="android:textAllCaps">true</item> but this has no effect when I put it in the actionBar style or actionBar's titleTextStyle. It only has an effect when I put in in the AppTheme style but that makes a bunch of things in my app also in all caps which I don't want.
My styles:
<style name="AppTheme" parent="AppBaseTheme">
<!-- snip snip -->
<item name="android:actionBarStyle">#style/NewActionBar</item>
</style>
<style name="NewActionBar" parent="#style/Widget.AppCompat.ActionBar">
<item name="android:background">#color/text_pink</item> <!-- no effect -->
<item name="android:titleTextStyle">#style/NewActionBarTitle</item>
<item name="android:displayOptions">showHome|showTitle</item>
<item name="android:textAllCaps">true</item> <!-- no effect -->
</style>
<style name="NewActionBarTitle">
<item name="android:textSize">#dimen/tiny_text_size</item> <!-- no effect -->
<item name="android:textAllCaps">true</item> <!-- no effect -->
</style>
And why do the NewActionBar and NewActionBarTitle styles appear to have no effect no matter what I put in them? Is there something wrong with my styles or my action bar or what?
Edit: I've just deleted entirely the styles NewActionBar and NewActionBarTitle (and the reference to them in the AppTheme style) and the action bar looks completely the same. So something is broken. What could it be?
You need to set android:textAllCaps="true" on the text appearance for the action bar's title, rather than the action bar style itself or on your base activity theme.
<style name="AppTheme" parent="AppBaseTheme">
...
<item name="actionBarStyle">#style/Widget.MyApp.ActionBar.Solid</item>
</style>
<style name="Widget.MyApp.ActionBar.Solid"
parent="Widget.AppCompat.ActionBar.Solid">
<item name="titleTextStyle">#style/TextAppearance.MyApp.Widget.ActionBar.Title</item>
</style>
<style name="TextAppearance.MyApp.Widget.ActionBar.Title"
parent="TextAppearance.AppCompat.Widget.ActionBar.Title">
<item name="android:textAllCaps">true</item>
</style>