I want a red toolbar (white icons and white text) but with a popup that has a light background. I cant get the popup background to change to light unless i use a .Light actionbar, which is a problem because it gives me black actionbar text and icons which I don't want
<android.support.v7.widget.Toolbar
android:id="#+id/my_awesome_toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:background="?attr/colorPrimary"
android:minHeight="?attr/actionBarSize"
android:popupTheme="#style/ThemeOverlay.AppCompat.Dark"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar" />
I tried changing android:popupTheme="#style/ThemeOverlay.AppCompat.Dark" to android:popupTheme="#style/ThemeOverlay.AppCompat.Light" but it makes no difference
Here is my theme
<style name="AppBaseTheme" parent="Theme.AppCompat.Light.NoActionBar"></style>
<style name="AppTheme" parent="AppBaseTheme">
<item name="colorPrimary">#color/primary</item>
<item name="colorPrimaryDark">#color/primary_dark</item>
<item name="colorAccent">#color/accent</item>
<!-- <item name="windowActionBar">false</item> -->
</style>
Finally I managed to get it to change
<style name="AppTheme" parent="AppBaseTheme">
<item name="colorPrimary">#color/primary</item>
<item name="colorPrimaryDark">#color/primary_dark</item>
<item name="colorAccent">#color/accent</item>
<item name="windowActionBar">false</item>
<item name="android:textColor">#android:color/black</item>
<item name="android:textColorPrimary">#android:color/white</item>
<item name="android:actionMenuTextColor">#android:color/black</item>
</style>
<android.support.v7.widget.Toolbar
android:id="#+id/my_awesome_toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:background="#color/primary"
android:minHeight="?attr/actionBarSize"
android:theme="#style/ThemeOverlay.AppCompat.ActionBar" />
I don't think there is any way to do this using theme.
You need to do this using Android Action Bar Style Generator
Related
I have different themes in styles.xml and I have used different background color in each theme.
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
<item name="android:background">#color/transparent</item>
</style>
<style name="AppThemeDark" parent="Theme.AppCompat">
<item name="colorPrimary">#android:color/transparent</item>
<item name="colorPrimaryDark">#android:color/black</item>
<item name="colorAccent">#color/colorAccent</item>
<item name="android:background">#181818</item>
</style>
<style name="AppThemeLight" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimary">#color/colorPrimaryLight</item>
<item name="colorPrimaryDark">#color/colorPrimaryDarkLight</item>
<item name="colorAccent">#color/colorAccentLight</item>
<item name="android:background" >#color/backgroundLight</item>
</style>
xml snippet,
<android.support.design.widget.CoordinatorLayout 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="match_parent"
android:fitsSystemWindows="true">
<include layout="#layout/content_main" />
<android.support.design.widget.AppBarLayout
android:background="#android:color/transparent"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:elevation="0dp"
android:theme="#style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:background="#android:color/transparent"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:popupTheme="#style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
</android.support.design.widget.CoordinatorLayout>
When I change the theme, the title background also changed to that color.
I tried using the following in each theme,But it doesn't work.
<item name="android:windowTitleBackgroundStyle">#style/titletheme</item>
And titletheme ,
<style name="titletheme">
<item name="android:background">#00000000</item>
</style>
See the image, the title background is changed with android:background color in that theme.
How to prevent change of the title background color?
Just change one thing and tell me its working or not: remove "android:background" from your theme and add "android:windowBackground". see if this helps. rest leave the same.
I'm trying to change my Toolbar's menu item text color here, but it doesn't work. Here's my style:
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
<item name="toolbarStyle">#style/AppTheme.ToolbarStyle</item>
<item name="buttonStyle">#style/AppTheme.ButtonStyle</item>
<item name="colorControlHighlight">#color/colorPrimary</item>
</style>
<style name="AppTheme.ToolbarStyle" parent="Base.Theme.AppCompat.Light.DarkActionBar">
<item name="android:background">#color/colorPrimary</item>
<item name="titleTextColor">#android:color/white</item>
<item name="titleTextAppearance">#style/TextAppearance.AppCompat.Widget.ActionBar.Title
</item>
<item name="actionMenuTextColor">#android:color/white</item>
</style>
layout xml:
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:title="#string/app_name"
app:titleMarginStart="#dimen/margin_l"
/>
I have tried to set the Toolbar theme directly in xml, but the menu item is still back. Is there a solution to this?
Add these lines in your AppTheme style
<item name="actionMenuTextColor">#color/white</item>
<item name="android:actionMenuTextColor">#color/white</item>
Having a material toolbar you can play with styling modifying text title and menu texts as follows:
<com.google.android.material.appbar.MaterialToolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?actionBarSize"
android:background="#android:color/white"
android:elevation="6dp"
android:theme="#style/App.ToolbarStyle"
app:titleTextAppearance="#style/App.ToolbarTitleTex"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:menu="#menu/create_item_menu"
app:titleTextColor="#android:color/black" />
Where this style lets you change the color of the icon of the left:
<style name="App.ToolbarStyle" parent="ThemeOverlay.MaterialComponents.Toolbar.Primary">
<item name="colorOnPrimary">#color/colorPrimary</item>
</style>
Also you can change the title text appearance with another style:
<style name="App.ToolbarTitleTex" parent="ThemeOverlay.MaterialComponents.Toolbar.Primary">
<item name="android:textSize">18sp</item>
<item name="fontFamily">#font/roboto_bold</item>
</style>
And finally to change the menu item style you need to add this item property to the main style/theme of the app (the one you set in the AndroidManifest file:
<item name="actionMenuTextAppearance">#style/App.ToolbarMenuItem</item>
With:
<style name="App.ToolbarMenuItem" parent="ThemeOverlay.MaterialComponents.Toolbar.Primary">
<item name="android:textSize">14sp</item>
<item name="fontFamily">#font/roboto_bold</item>
<item name="textAllCaps">true</item>
<item name="android:textStyle">bold</item>
</style>
The final result would be something like this:
You need to declare a Theme like this
<style name="Theme.PopupOverlay.Menu" parent="ThemeOverlay.AppCompat.Light" >
<item name="android:textColor">#android:color/white</item>
</style>
And then, in your Toolbar in layout view you must specify to use that theme
<androidx.appcompat.widget.Toolbar xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="#style/Theme.PopupOverlay.Menu" />
Modern way under Material3 theming.
<style name="AppTheme" parent="Theme.Material3.Dark">
<item name="toolbarStyle">#style/ToolBarStyle</item>
...
</style>
<style name="ToolBarStyle" parent="#style/Widget.Material3.Toolbar">
<item name="titleTextColor">#android:color/holo_green_light</item>
<item name="navigationIconTint">#android:color/holo_blue_light</item>
<item name="materialThemeOverlay">#style/ToolbarThemeOverlay</item>
</style>
<style name="ToolbarThemeOverlay" parent="">
<item name="actionMenuTextColor">#android:color/holo_red_light</item>
</style>
materialThemeOverlay - is the key to apply the colors to action menu items
In your theme file you have to put this :
<style name="AppTheme.ActionBar" parent="Theme.AppCompat.Light.DarkActionBar">
...
<item name="actionMenuTextColor">#color/text_color</item>
...
</style>
and apply above theme to Toolbar view as like this android:theme="#style/AppTheme.ActionBar"
detailed example:
<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/main_toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
android:layout_gravity="top"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light"
android:theme="#style/AppTheme.ActionBar"/>
I tried everything one by one present on links like
How to change color of the back arrow in the new material theme?
How to change Toolbar home icon color
Change toolbar back arrow color
How to change change text and arrow color on Toolbar?
Android: unable to change color of back arrow navigation icon
etc,
But nothing works for me.
My layout xml code,
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
style="#style/MyCustomTabLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:background="?attr/colorPrimary"
android:elevation="6dp"
android:minHeight="?attr/actionBarSize"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light" />
<android.support.design.widget.TabLayout
android:id="#+id/tab_layout"
style="#style/MyCustomTabLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:minHeight="?attr/actionBarSize"
app:tabMaxWidth="0dp" />
in styles.xml
<style name="MyCustomTabLayout" parent="Theme.AppCompat.Light">
<item name="tabIndicatorHeight">2dp</item>
<item name="tabPaddingStart">12dp</item>
<item name="android:layout_width">match_parent</item>
<item name="tabPaddingEnd">12dp</item>
<item name="tabBackground">#drawable/background_tab_item</item>
<item name="tabIndicatorColor">#color/jd_yellow</item>
<item name="android:layout_gravity">center</item>
<item name="android:gravity">center</item>
<item name="tabSelectedTextColor">#color/jd_white</item>
<item name="tabTextAppearance">#style/MyCustomTabTextAppearance</item>
<item name="android:textAppearance">#style/MyCustomTabTextAppearance</item>
<item name="android:background">#drawable/background_tab_item</item>
<item name="android:textColorSecondary">#color/jd_white</item>
<item name="colorControlNormal">#color/jd_white</item>
<item name="drawerArrowStyle">#style/DrawerArrowStyle</item>
<item name="actionBarTheme">#style/MyApp.ActionBarTheme</item>
<item name="actionBarWidgetTheme">#style/WidgetStyle</item>
<item name="colorPrimary">#color/jd_white</item>
<item name="colorPrimaryDark">#color/jd_white</item>
<item name="android:textColorPrimary">#color/jd_white</item>
</style>
<style name="WidgetStyle" parent="style/ThemeOverlay.AppCompat.Light">
<item name="colorControlNormal">#color/jd_white</item>
</style>
<style name="MyApp.ActionBarTheme" parent="#style/ThemeOverlay.AppCompat.ActionBar">
<!-- change color the arrow or three lines -->
<item name="colorControlNormal">#color/jd_white</item>
</style>
<!-- Style for the navigation drawer icon -->
<style name="DrawerArrowStyle" parent="Widget.AppCompat.DrawerArrowToggle">
<item name="spinBars">true</item>
<item name="color">#color/jd_white</item>
</style>
<style name="MyCustomTabTextAppearance" parent="TextAppearance.Design.Tab">
<item name="android:textColor">#color/jd_white</item>
<item name="android:textSize">#dimen/tab_layout_text_size</item>
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">match_parent</item>
<item name="android:layout_gravity">center</item>
<item name="android:gravity">center</item>
</style>
Also tried adding below to onCreate()
Drawable upArrow = ContextCompat.getDrawable(mContext, R.drawable.abc_ic_ab_back_material);
upArrow.setColorFilter(ContextCompat.getColor(mContext, R.color.white), PorterDuff.Mode.SRC_ATOP);
getSupportActionBar().setHomeAsUpIndicator(upArrow);
Nothing working, still it's color is black,
What wrong I'm doing?? Please help.
Very simple, this worked for me:
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="56dp"
android:background="#color/PrimaryColor"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light"
android:elevation="4dp" />
You could make your own asset in whatever colour you like and then place it on the toolbar.
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeAsUpIndicator(R.drawable.YOUR_ASSET);
Try using this style as your android:theme for Toolbar:
<style name="ToolbarStyle" parent="#style/ThemeOverlay.AppCompat.Dark">
<item name="android:textColorSecondary">#color/jd_white</item>
</style>
like
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
style="#style/MyCustomTabLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:background="?attr/colorPrimary"
android:elevation="6dp"
android:minHeight="?attr/actionBarSize"
android:theme="#style/ToolbarStyle"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light" />
after countless hack and plain weird situations , this works like charm
<style name="App"/>
<style name="App.Toolbar">
<item name="android:id">#id/toolbar</item>
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">?attr/actionBarSize</item>
<item name="android:background">#android:color/white</item>
<item name="android:minHeight">?attr/actionBarSize</item>
<item name="android:theme">#style/ThemeOverlay.AppCompat.Light</item>
<item name="popupTheme">#style/ThemeOverlay.AppCompat.Dark</item>
</style>
<style name="App.Toolbar.Transparent">
<item name="android:background">#android:color/transparent</item>
</style>
This is my main activity xml:
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="#style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
<include layout="#layout/content_main" />
<android.support.design.widget.FloatingActionButton
android:id="#+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="#dimen/fab_margin"
android:src="#android:drawable/ic_menu_search" />
This is my styles.xml
<style name="AppTheme" parent="Theme.AppCompat.Light">
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
</style>
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar">
</style>
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
The problem is that I want to use white text on the AppBar, but at the same time I want the search suggestions to have dark text on white background (like holo). Currently the suggestions are shown in dark theme. If I use ThemeOverlay.AppCompat.ActionBar, then the suggestions turn white but the text on appbar is turned Black, and I want it to remain white.
Please help me! I am also attaching screenshots for demonstration purposes:
This has white title text.
see the dropdown suggestions? they should be white-themed.
Here is how I succeeded to achieve that:
You need to override the styles autoCompleteTextViewStyle and textAppearanceSearchResultTitle in your theme:
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="autoCompleteTextViewStyle">#style/myAutoCompleteTextViewStyle</item>
<item name="textAppearanceSearchResultTitle">#style/mySearchResult</item>
...
</style>
<style name="myAutoCompleteTextViewStyle" parent="Widget.AppCompat.Light.AutoCompleteTextView">
<item name="android:popupBackground">#color/White</item>
</style>
<style name="mySearchResult" parent="TextAppearance.AppCompat.SearchResult.Title">
<item name="android:textColor">#color/Black</item>
</style>
Toolbar ActionMode seems to ignore my style on devices pre Lollipop.
Here is my style:
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowNoTitle">true</item>
<!--We will be using the toolbar so no need to show ActionBar-->
<item name="windowActionBar">false</item>
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
<item name="windowActionModeOverlay">true</item>
<item name="android:textColorPrimary">#DD000000</item>
<item name="android:textColorSecondary">#8A000000</item>
<!-- Set theme colors from http://www.google.com/design/spec/style/color.html#color-color-palette-->
<!-- colorPrimary is used for the default action bar background -->
<!-- Set AppCompat’s color theming attrs -->
<item name="colorPrimary">#color/primary</item>
<item name="colorPrimaryDark">#color/secondary</item>
<item name="colorAccent">#color/accent</item>
<item name="android:actionModeStyle">#style/Widget.ActionMode</item>
<item name="android:actionModeBackground">#drawable/toolbar_action_background</item>
<item name="android:actionModeCloseDrawable">#drawable/ic_arrow_back_white_24dp</item>
</style>
<style name="Widget.ActionMode" parent="#style/Widget.AppCompat.ActionMode">
<item name="android:background">#drawable/toolbar_action_background</item>
<item name="android:titleTextStyle">#style/TitleTextStyle</item>
</style>
<style name="TitleTextStyle" parent="#style/TextAppearance.AppCompat.Widget.ActionBar.Title">
<item name="android:textColor">#fff</item>
</style>
And my toolbar xml
<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:elevation="4dp"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:minHeight="?attr/actionBarSize"
app:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light"
android:background="?attr/colorPrimary" />
I've checked these questions:
How to specify dark action mode with my theme
Toolbar and Contextual ActionBar with AppCompat-v7
Unable to style action mode when using Toolbar
Expected behaviour, works fine on lollipop:
How it looks on kitkat:
Solved by specifying booth android namspace and without in my theme:
...
<item name="actionModeStyle">#style/ActionMode</item>
<item name="android:actionModeStyle">#style/ActionMode</item>
...
<style name="ActionMode" parent="Widget.AppCompat.ActionMode">
<item name="android:background">#drawable/toolbar_action_background</item>
<item name="background">#drawable/toolbar_action_background</item>
</style>
Look at your Toolbar's theme:
app:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"
The first style, you didn't give a name. You missed some lines. Then, let's suppose the style which has no name, its name is ToolbarStyle which has a line of <item name="colorPrimary">#color/primary</item> which does matter. Then at your Toolbar layout, replace your app:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar" by app:theme="#style/ToolbarStyle". Then <item name="colorPrimary">#color/primary</item> will color your Toolbar's background. Are we clear now?