app:popupTheme not applying to both overflow menus - android

The popup overflow menu on the toolbar works fine however when I pressed the menu button on my phone, it's overflow menu (the one at the bottom of the screen) still inherits the toolbar theme which I've set to the dark theme to get the white text.
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:title="#string/app_name"
android:background="?attr/colorPrimary"
app:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light"
/>
The theme of my app is set to the AppTheme which inherits Theme.AppCompat.Light.NoActionBar. It's the default values for now.
<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/colorAccent</item>
</style>
I'm still new to Android so I'm not sure if I'm overlooking a simple mistake or if it's a simple fix.

Related

Android: StatusBar White after setting fitsSystemWindows and toolbar having a primaryDarkColor

I have been debugging this for quite sometime and cannot seem to find the solution. My problem is that my statusbar is white even when I have my view with the xml line
android:fitsSystemWindows="true"
A picture of the problem can be found below. Anyway, I have tried multiple solutions, but none have worked. Here is the code for my toolbar.
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.AppBarLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:elevation="3dp"
>
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
style="#style/AppTheme.ActionBarStyle"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="#color/actionbar_color"/>
</android.support.design.widget.AppBarLayout>
Here is the code for AppTheme.ActionBarStyle
<style name="AppTheme.ActionBarStyle" parent="Widget.AppCompat.Toolbar">
<item name="android:background">#color/actionbar_color</item>
<item name="popupTheme">#style/ThemeOverlay.AppCompat.Light</item>
<item name="theme">#style/ThemeOverlay.AppCompat.Light</item>
</style>
Here is a picture of the problem. What am I missing here? Also note that I did set the colors in the apptheme
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Set AppCompat’s color theming attrs -->
<item name="colorPrimary">#color/primary</item>
<!-- darker variant for the status bar and contextual app bars -->
<item name="colorPrimaryDark">#color/primary_dark</item>
<!-- theme UI controls like checkboxes and text fields -->
<item name="colorAccent">#color/accent</item>
</style>
If your phone is pre-Lollipop then you will not be able to achieve it like this.Code you have written is correct and will show correctly on Lollipop devices.
Adding these style settings to your AppTheme may work:
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
<item name="android:statusBarColor">#color/colorPrimaryDark</item>
Note that this can work only for API-21 (Lollipop) or later.
This is a bit embarrassing, but I was using a different style in my Manifest file. That is why it wasn't working.

Change overflow and home icon color in android

Im developing an android application with minimum API Level 10 (2.3.3) and im using the toolbar as my actionbar. Both the home icon and the overflow icon and also the title text color are white on Honeycomb and above which is what i want. The problem is on below honeycomb, the home icon, the overflow icon and the titleColor are black and i want them also be white. How do i go about doing this. Below is my code.
styles.xml
<style name="Theme.DesignDemo" parent="Base.Theme.DesignDemo">
</style>
<style name="Base.Theme.DesignDemo" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">#color/primary</item>
<item name="colorPrimaryDark">#color/primaryDark</item>
<item name="colorAccent">#color/accent</item>
<item name="android:windowBackground">#color/window_background</item>
<item name="android:windowAnimationStyle">#style/MyAwesomeAnimation</item>
</style>
toolbar
<android.support.design.widget.AppBarLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:layout_scrollFlags="scroll|enterAlways"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light" />
I was having the exact same issue. Both the overflow and the homeAsUp icons were black in API level 11 and below. The following additional line in the application theme solved the problem
<item name="android:textColorSecondary">#android:color/white</item>
See also AppCompat Toolbar: Change Overflow Icon Color in ActionMode

Android custom toolbar theme not being applied

I have an app that uses a custom Toolbar style. Previously, it applied the theme correctly, but after a recent update of Android Studio, it has stopped working correctly.
The theme.xml is defined like so:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="OurTheme.Base" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:actionBarStyle">#style/MyActionBar</item>
<item name="android:buttonStyle">#style/ButtonAppTheme</item>
<item name="android:imageButtonStyle">#style/ImageButtonAppTheme</item>
<item name="android:listSeparatorTextViewStyle">#style/BlueListSeparatorTextViewStyle</item>
<item name="drawerArrowStyle">#style/DrawerArrowStyle</item>
<!-- colorPrimary is used for the default action bar background -->
<item name="colorPrimary">#color/action_bar_color</item>
<!-- colorPrimaryDark is used for the status bar -->
<!--<item name="colorPrimaryDark">#color/my_awesome_darker_color</item>-->
<!-- colorAccent is used as the default value for colorControlActivated
which is used to tint widgets -->
<item name="colorAccent">#color/btn_accent_color</item>
</style>
<!-- Application theme. -->
<style name="OurTheme" parent="OurTheme.Base">
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
<item name="android:listSeparatorTextViewStyle">#style/BlueListSeparatorTextViewStyle</item>
<item name="drawerArrowStyle">#style/DrawerArrowStyle</item>
</style>
</resources>
Our styles.xml contains:
<!-- ActionBar styles ThemeOverlay.AppCompat.ActionBar -->
<style name="MyActionBar" parent="Widget.AppCompat.ActionBar">
<item name="android:titleTextStyle">#style/MyActionBarTitleText</item>
</style>
<!-- ActionBar title text -->
<style name="MyActionBarTitleText" parent="TextAppearance.AppCompat.Widget.ActionBar.Title">
<item name="android:textColor">#color/actionbar_text</item>
</style>
actionbar_text is defined in our colors.xml:
<color name="actionbar_text">#ffffffff</color>
Finally, our custom toolbar layout:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
android:minHeight="?attr/actionBarSize"
app:theme="#style/ThemeOverlay.AppCompat.Dark" />
Previously, this worked and our app had white text in its custom toolbar. It now defaults to black everywhere in the app and the only method I have found that can change the color of the toolbar title text (other than doing it in code) is to change the toolbar layout to this:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
android:minHeight="?attr/actionBarSize"
app:titleTextAppearance="#style/MyActionBarTitleText"
app:theme="#style/ThemeOverlay.AppCompat.Dark" />
Note that now I am specifically telling the actionbar to use MyActionBarTitleText style.
I have also tried to specifically tell it to use the custom theme here as well, by changing the "app:theme" to:
app:theme="#style/MyActionBar"
but this hasn't helped.
I'm afraid I'm at a loss. I know the base theme works as I can change the background colour, but using the actionBarStyle item simply refuses to work.
This has also affected text layouts and justifications to some of our custom button layouts as well and I can't figure out why it has stopped working. Does anyone have any suggestions?
It's very late but answering it.
Create a custom theme for your toolbar and set android:background
<style name="ToolbarStyle" parent="Widget.AppCompat.Toolbar">
<item name="android:background">#color/blue</item> // change your color here and add other attributes
</style>
Now apply this theme to your toolbar in XML like:
style="#style/ToolbarStyle"

AppCompat toolbar dark theme style not working on pre 21 devices

First of all I have repeatedly read and applied everything posted here, but it does not solve my problem. It seems that every answer posted here is to apply style to theme attribute of the toolbar, i've tried it it got me nowhere, so let me explain what my problem is:
I want to have light theme everywhere except the toolbar. On Lollipop devices, it's not a problem, but on pre Lollipop devices toolbars Title and overflow button always adopts MyTheme parent style, so I get dark Title and dark overflow button (it's my only button there) it seems like theme attribute is malfunctioning in Toolbar.
I'm using AppCompatActivity for my base class, my minimum api is 15 and AppCompat version is 22.2.1.0
Here's my code:
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:local="http://schemas.android.com/apk/res-auto"
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?attr/actionBarSize"
android:background="?attr/colorPrimary"
local:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"
local:popupTheme="#style/ThemeOverlay.AppCompat.Light"/>
<style name="MyTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="windowNoTitle">true</item>
<item name="windowActionBar">false</item>
<item name="colorPrimary">#color/primary_color</item>
<item name="colorPrimaryDark">#color/dark_primary_color</item>
<item name="colorAccent">#color/accent_color</item>
<item name="android:statusBarColor">#color/dark_primary_color</item>
<item name="selectableItemBackground">?android:attr/selectableItemBackground</item>
</style>
my hamburger item is white because I inflate image from resource
var toolbar = FindViewById<Toolbar>(Resource.Id.toolbar);
SetSupportActionBar(toolbar);
SupportActionBar.Title = "Sport";
if (Build.VERSION.SdkInt >= BuildVersionCodes.Lollipop)
Window.AddFlags(WindowManagerFlags.DrawsSystemBarBackgrounds);
if (SupportActionBar != null){
SupportActionBar.SetHomeAsUpIndicator(Resource.Drawable.ic_menu_white_24dp);
SupportActionBar.SetDisplayHomeAsUpEnabled(true);
}
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/colorPrimary"
app:theme="#style/ThemeOverlay.AppCompat.Dark"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light"
>
</android.support.v7.widget.Toolbar>
Try This combination in your toolbar code it should work just fine.
This is what worked for me in the end:
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:local="http://schemas.android.com/apk/res-auto"
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?attr/actionBarSize"
android:background="?attr/colorPrimary"
local:titleTextColor="#android:color/white"
local:theme="#style/ToolbarTheme"
local:popupTheme="#style/ThemeOverlay.AppCompat.Light" />
<style name="ToolbarTheme" parent="#style/ThemeOverlay.AppCompat.Dark.ActionBar">
<item name="android:background">#color/primary_color</item>
<!-- Used to for the title of the Toolbar -->
<item name="android:textColorPrimary">#fff</item>
<!-- Used to for the title of the Toolbar when parent is Theme.AppCompat.Light -->
<item name="android:textColorPrimaryInverse">#fff</item>
<!-- Used to color the text of the action menu icons -->
<item name="android:textColorSecondary">#fff</item>
<!-- Used to color the overflow menu icon -->
<item name="actionMenuTextColor">#fff</item>
</style>
<style name="MyTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">#color/primary_color</item>
<item name="colorPrimaryDark">#color/dark_primary_color</item>
<item name="colorAccent">#color/accent_color</item>
<item name="android:statusBarColor">#color/dark_primary_color</item>
<item name="colorControlNormal">#fff</item>
</style>
In this case ColorControlNormal colored overflow icon and titleTextColor colored Title. It seems that in my case ToolbarTheme doesn't work. I don't have a clue why is it, but now I don't care. This is not an optimal solution but it works.

AppCompat Toolbar: Change Overflow Icon Color in ActionMode

With the AppCompat Toolbar, I want to be able to change the color of the overflow menu icon on ActionMode change.
For example, the overflow icon will be white in normal Toolbar mode. And will turn black on ActionMode. So far, I have managed to change the background of the action mode as well as the title text. But I have yet to find a way to change the overflow menu icon color.
I know that there's an answer available:
Change ActionMode Overflow icon
I tried the first solution and I wasn't able to find the overflow icon.
The second solution, even with a 50L delay causes the overflow menu icon to flash the ActionMode's intended color for a brief split second that is very jarring.
Add the below line into your theme attribute:
<item name="android:textColorSecondary">#android:color/white</item>
This can be achieved by setting the android:textColorSecondary theme attribute.
For example, suppose you have the following toolbar, which uses the theme MyToolbarStyle:
<android.support.v7.widget.Toolbar
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/main_toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?attr/actionBarSize"
theme="#style/MyToolbarStyle"
/>
Next, define the style MyToolbarStyle, inheriting from ThemeOverlay.AppCompat.ActionBar. Finally, modify the color of the overflow icon by adding an item for android:textColorSecondary:
<style name="MyToolbarStyle" parent="ThemeOverlay.AppCompat.ActionBar">
<item name="android:textColorSecondary">#333333</item>
</style>
<style name="AppTheme" parent="Theme.AppCompat.NoActionBar">
<item name="android:actionOverflowButtonStyle">#style/ActionButton.Overflow.Icon</item>
</style>
<style name="ActionButton.Overflow.Icon" parent="android:style/Widget.Holo.Light.ActionButton.Overflow">
<item name="android:src">#mipmap/yourwanticon</item>
</style>
<style name="AppTheme" parent="Theme.AppCompat.Light">
<item name="android:actionOverflowButtonStyle">#style/ActionButtonOverflow</item>
<!-- Support library compatibility -->
<item name="actionOverflowButtonStyle">#style/ActionButtonOverflow</item>
</style>
<style name="ActionButtonOverflow" parent="#style/Widget.AppCompat.ActionButton.Overflow">
<item name="android:tint">#color/brand_white</item>
</style>
Add this code on your res->styles.xml
<style name="ToolbarColored" parent="AppTheme">
<item name="android:textColorSecondary">YOUR_COLOR</item>
</style>
Then your 'ToolbarColored' style in your XML file like belove
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
app:theme="#style/ToolbarColored"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="#style/AppTheme.PopupOverlay" />
<style name="ToolBarTheme" parent="ThemeOverlay.AppCompat.ActionBar">
<item name="android:tint">#color/colorAccent</item>
create the above theme.set tint with your color and add this theme to the toolbar.
<androidx.appcompat.widget.Toolbar
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?attr/actionBarSize"
android:theme="#style/ToolBarTheme"/>
To correctly change the color of your toolbar's overflow menu icon, set your toolbar's theme to an AppCompat dark ActionBar theme. For example:
In your res/values/style.xml file create a theme that inherits from AppCompat in this manner:
<style name="AppTheme.MyThemeName" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
Now set your toolbar's theme to this theme:
<android.support.v7.widget.Toolbar
android:id="+id/my_toolbar_id
android:layout_width="match_parent"
android:layout_height="#dimen/my_toolbar_height"
android:theme="#style/AppTheme.MyThemeName">
</android.support.v7.widget.Toolbar>
None of the answers here helped me change the overflow icon color of ActionMode independently from the overflow icon color of the normal Toolbar (without resorting to case-by-case styling in code). After some trial and error, I thought that we might override theme attribute of ActionMode independently from Toolbar, and it worked!
In the base theme, we specify the style of action mode like usual:
<style name="BaseTheme" parent="Theme.MaterialComponents.DayNight.Bridge">
<item name="actionModeStyle">#style/ActionModeStyle</item>
</style>
In our custom ActionModeStyle we do whatever styling we want, and also specify a theme attribute:
<style name="ActionModeStyle" parent="#style/Widget.AppCompat.ActionMode">
<item name="theme">#style/ActionMode.Theme</item>
</style>
<style name="ActionMode.Theme" parent="ThemeOverlay.AppCompat.Dark">
<item name="android:textColorSecondary">?attr/colorPrimary</item>
</style>
textColorSecondary will also change the back button color, but we can easily override that one using actionModeCloseButtonStyle.
First make your custom style
<style name="ToolbarColoredBackArrow" parent="AppTheme">
<item name="android:textColorSecondary">#color/white</item>
</style>
Then just add it into your toolbar
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:titleTextColor="#color/white"
app:theme="#style/ToolbarColoredBackArrow"
android:layout_height="?attr/actionBarSize"
app:layout_scrollFlags="scroll|enterAlways"
android:background="?attr/colorPrimary" />
If you are using the toolbar in your activity xml you can use something like this
toolbar?.navigationIcon?.setColorFilter(ContextCompat.getColor(this, android.R.color.black), PorterDuff.Mode.SRC_ATOP)
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="actionOverflowButtonStyle">#style/CustomOverflowButtonStyle</item>
</style>
<style name="CustomOverflowButtonStyle" parent="Widget.AppCompat.ActionButton.Overflow">
<item name="android:tint">#color/black</item>
</style>
If you want the white overflow menu icon simply add
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar" to your Toolbar layout code.
If you want the dark overflow menu icon use
android:theme="#style/Base.Widget.AppCompat.Light.PopupMenu"
So final code is something like:
<android.support.v7.widget.Toolbar
android:id="#+id/a_main_tb"
android:layout_width="match_parent"
android:layout_height="?actionBarSize"
android:background="#color/colorPrimary"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:title="#string/app_name"
app:titleTextColor="#ffffff"
/>
Also, you should understand that it will change the color of the menu items also.

Categories

Resources