I've tried many things to change the text color when i click the "three dot" menu button but it always reverts back to the toolbar (android:theme) theme and not the android:popupTheme. I want the text to be black but it always shows up white.
styles.xml
<!-- Base application theme. -->
<style name="AppTheme" parent="AppTheme.Base">
<!-- Customize your theme here. -->
</style>
<style name="AppTheme.Base" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/primaryColor</item>
<item name="colorPrimaryDark">#color/primaryColorDark</item>
<item name="colorAccent">#color/accentColor</item>
</style>
<style name="MaterialWorkout_theme" parent="ThemeOverlay.AppCompat.Light">
<item name="android:textColorPrimary">#FFFFFF</item>
<item name="android:textColorSecondary">#48FFFFFF</item>
</style>
<style name="Popup_theme" parent="ThemeOverlay.AppCompat.Light">
<item name="android:textColorPrimary">#000000</item>
<item name="android:textColorSecondary">#38000000</item>
</style>
app_bar.xml
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#color/primaryColor"
android:id="#+id/app_bar"
android:theme="#style/MaterialWorkout_theme"
android:popupTheme="#style/Popup_theme"
>
Here is what it looks like:
http://imgur.com/svRuuHK
Solved it. changed my toolbar.xml file to this:
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:background="#color/primaryColor"
android:id="#+id/tool_bar"
android:theme="#style/MaterialWorkout_theme"
app:popupTheme="#style/Popup_theme">
notice the implementation of:
xmlns:app="http://schemas.android.com/apk/res-auto"
and
app:popupTheme="#style/Popup_theme"
these two lines solved my problem!
You need to define your popup menu theme in your style, not you Toolbar.
<style name="AppTheme.Base" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/primaryColor</item>
<item name="colorPrimaryDark">#color/primaryColorDark</item>
<item name="colorAccent">#color/accentColor</item>
<item name="popupMenuStyle">#style/Popup_theme</item>
</style>
Use below code .I hope this will solve your problem.You can change both background color and textcolor.
<style name="AppFullScreenThemeNight" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowNoTitle">true</item>
<item name="android:windowActionBar">false</item>
<item name="android:windowFullscreen">false</item>
<item name="android:windowContentOverlay">#null</item>
<item name="android:popupMenuStyle">#style/PopupMenu</item>
<!-- if using android.support.v7.widget.PopupMenu -->
<item name="popupMenuStyle">#style/PopupMenu</item>
<item name="android:itemTextAppearance">#style/TextAppearance</item>
</style>
<style name="PopupMenu" parent="ThemeOverlay.AppCompat.ActionBar">
<item name="android:popupBackground">#color/button_color</item>
</style>
<style name="TextAppearance">
<item name="android:textColor">#android:color/holo_red_dark</item>
</style>
Related
T'm using the newest Android Studio Version to code my app and I can't change the button style.
It seems like when generating a new project, it already has some default styles for buttons which I can't seem to be able to override.
Everytime I place just a plane button it already has some background color ("colorPrimary") and if I'm trying to apply a style, it only changes the text of the button, but not the shape or the color.
This is my style:
<style name="buttonStartStyle">
<item name="android:background">#drawable/button_style1</item>
<item name="android:layout_margin">20dp</item>
<item name="android:textColor">#color/white</item>
<item name="android:textAllCaps">false</item>
<item name="android:textSize">18sp</item>
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">wrap_content</item>
</style>
and my button_style1.xml:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<corners android:radius="50dp"/>
<solid android:color="#color/smoothWhite"/>
<size android:height="50dp"/>
<gradient android:startColor="#color/green_card" android:endColor="#color/green_main"/>
</shape>
</item>
The button already looks like this when I place it right from the pallete:
My xml code for the button:
<Button
android:id="#+id/button"
style="#style/buttonStartStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button"
tools:layout_editor_absoluteX="121dp"
tools:layout_editor_absoluteY="244dp" />
This is how the button looks with the style applied:
Here is my themes.xml:
<resources xmlns:tools="http://schemas.android.com/tools">
<!-- Base application theme. -->
<style name="Theme.B_app" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
<!-- Primary brand color. -->
<item name="colorPrimary">#color/green_dark</item>
<item name="colorPrimaryVariant">#color/black</item>
<item name="colorOnPrimary">#color/white</item>
<!-- Secondary brand color. -->
<item name="colorSecondary">#color/teal_200</item>
<item name="colorSecondaryVariant">#color/teal_700</item>
<item name="colorOnSecondary">#color/black</item>
<!-- Status bar color. -->
<item name="android:statusBarColor" tools:targetApi="l">?attr/colorPrimaryVariant</item>
<!-- Customize your theme here. -->
</style>
<style name="Theme.B_app.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<style name="Theme.B_app.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
<style name="Theme.B_app.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
<style name="buttonStartStyle">
<item name="android:background">#drawable/button_style1</item>
<item name="android:layout_margin">20dp</item>
<item name="android:textColor">#color/white</item>
<item name="android:textAllCaps">false</item>
<item name="android:textSize">18sp</item>
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">wrap_content</item>
</style>
<style name="testStyle">
<item name="android:background">#drawable/button_style2</item>
<item name="android:layout_margin">20dp</item>
<item name="android:textColor">#color/white</item>
<item name="android:textAllCaps">false</item>
<item name="android:textSize">18sp</item>
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">wrap_content</item>
</style>
<style name="FlatButton" parent="Theme.AppCompat.Light">
<item name="android:textColor">#color/grey_dark</item>
<item name="colorControlHighlight">#color/white</item>
</style>
I see two possibilites:
You might not have the right parent for your Button. Try:
<style name="buttonStartStyle" parent ="android:Widget.Button">
attributes might be changed along the way in your program. Try setting the needed attributes to null before applying the style.
The problem here is likely with the parent style in themes.xml.
If the parent theme is one of the Material Components ones for example:
<style name="Theme.StyleDemo2" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
<!-- Primary brand color. -->
<item name="colorPrimary">#color/purple_500</item>
<item name="colorPrimaryVariant">#color/purple_700</item>
<item name="colorOnPrimary">#color/white</item>
<!-- Secondary brand color. -->
<item name="colorSecondary">#color/teal_200</item>
<item name="colorSecondaryVariant">#color/teal_700</item>
<item name="colorOnSecondary">#color/black</item>
<!-- Status bar color. -->
<item name="android:statusBarColor" tools:targetApi="l">?attr/colorPrimaryVariant</item>
<!-- Customize your theme here. -->
</style>
This overrides any style changes you might make to give your button the material theme with a tint color defined by the colorPrimary item in the theme (they are also not standard buttons in this instance but some funky sub class replaced quietly). To overcome this issue change the parent theme to something such as:
parent="Theme.AppCompat.Light"
This one is much more customizable and your button styles will take effect.
I'm trying to change the colour of the selected icon in the bottom navigation bar. I already have a selector, that changes the colour of the selected icon. My problem is, that if the App theme changes, the colours won't change.
How can I change the selector colour, based on the App theme?
This is the selector I already have:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="#color/standardThemeAccentSelected" android:state_checked="true" />
<item android:color="#color/standardThemeAccentNonSelected" />
</selector>
Those are my themes/styles:
<resources>
<!-- Base application theme. -->
<style name="baseTheme" parent="Theme.AppCompat.Light">
<item name="colorPrimary">#color/standardThemePrimaryColor</item>
<item name="colorPrimaryDark">#color/standardThemePrimaryDark</item>
<item name="android:textColor">#color/standardThemeAccentText</item>
<item name="android:windowBackground">#color/standardThemeAccentBackground</item>
<item name="itemIconTint">#color/standardThemeAccentNonSelected</item>
<item name="itemTextColor">#color/standardThemeAccentNonSelected</item>
<item name="colorAccent">#color/standardThemeAccentContent</item>
<item name="drawableTint">#color/standardThemeAccentText</item>
<item name="bottomNavigationStyle">#style/baseThemeNav</item>
<!--Navigation-->
<item name="android:navigationBarColor">#color/standardThemePrimaryColor</item>
</style>
<!--Base Theme Nav-->
<style name="baseThemeNav" parent="Widget.Design.BottomNavigationView">
<item name="android:background">#color/standardThemePrimaryColor</item>
</style>
<!--Black Theme-->
<style name="blackTheme" parent="Theme.AppCompat">
<item name="colorPrimary">#color/blackThemePrimaryColor</item>
<item name="colorPrimaryDark">#color/blackThemePrimaryDark</item>
<item name="android:textColor">#color/blackThemeAccentText</item>
<item name="android:windowBackground">#color/blackThemeAccentBackground</item>
<item name="itemIconTint">#color/blackThemeAccentNonSelected</item>
<item name="itemTextColor">#color/blackThemeAccentNonSelected</item>
<item name="colorAccent">#color/blackThemeAccentContent</item>
<item name="drawableTint">#color/blackThemeAccentNonSelected</item>
<item name="bottomNavigationStyle">#style/blackThemeNav</item>
<!--Navigation Style-->
<item name="android:navigationBarColor">#color/blackThemePrimaryColor</item>
</style>
<!--Black Theme nav-->
<style name="blackThemeNav" parent="Widget.Design.BottomNavigationView">
<item name="android:background">#color/blackThemePrimaryColor</item>
</style>
</resources>
When I click item in the first picture I get something that you can see in the second picture. And as you can see I get white item. Does anyone know how to change its color?
https://i.stack.imgur.com/nkoNV.jpg
https://i.stack.imgur.com/JHQKO.jpg
menu.xml
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="#+id/tools"
android:title="123123" >
<group
android:checkableBehavior="all">
<menu >
<item
android:id="#+id/action_sort_az"
android:title="#string/sort_az"
android:checked="true"
app:showAsAction="never"
app:actionViewClass="android.widget.CheckBox" />
....
<item android:id="#+id/action_sort_id_asc"
android:title="#string/snachala_novye"
app:actionViewClass="android.widget.CheckBox" />
</menu>
</group>
</item>
</menu>
style.xml
<resources>
<!-- 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>
</style>
<style name="Theme.App.Base" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorControlNormal">#E9E2BF</item>
<item name="colorControlActivated">#E9E2BF</item>
<item name="colorControlHighlight">#E9E2BF</item>
</style>
<style name="customTheme" parent="Theme.AppCompat.DayNight.DarkActionBar">
<item name="android:itemBackground">#424242</item>
<item name="android:textColor">#E9E2BF</item>
<item name="colorPrimaryDark">#1b1b1b</item>
<item name="android:itemTextAppearance">#style/MyTextAppearance</item>
<item name="android:windowBackground">#color/mycolor</item>
</style>
...
</resources>
I see you have already modified the background colors of your menu items, which I also achieved by adding to my Style
<item name="android:itemBackground">#drawable/myColors</item> and then you have the issue with the Header of the SubMenu which is White or being really precise is <color name="material_grey_50">#fffafafa</color> applied automatically by the parent theme you are using Theme.AppCompat.DayNight.DarkActionBar.
To change the color of the header title of the submenu you will need your style.xml to have actionBarPopupTheme attribute and have the custom MyStyle style that I have written as below:
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.DayNight.DarkActionBar">
<!-- Customize your theme here. -->
<item name="android:itemBackground">#drawable/popup</item>
<item name="actionBarPopupTheme">#style/MyStyle</item>
</style>
<style name="MyStyle" parent="ThemeOverlay.AppCompat.Light">
<item name="android:colorBackground">#color/colorAccent</item>
</style>
</resources>
Add a custom style to your style.xml file with parent parent="#style/Widget.AppCompat.PopupMenu" and give it a popupBackground attribute
I am using support preference library and every PreferenceCategory fill the whole screen with blank space and then show the preferences that it contains. I have tried changing PreferenceCategory style attribute - layout_height to wrap_content and it didn't work.
My preference styles:
<style name="PreferenceThemeOverlay">
<item name="preferenceScreenStyle">#style/Preference.PreferenceScreen</item>
<item name="preferenceFragmentStyle">#style/PreferenceFragment</item>
<item name="preferenceCategoryStyle">#style/Preference.Category</item>
<item name="preferenceStyle">#style/Preference</item>
<item name="preferenceInformationStyle">#style/Preference.Information</item>
<item name="checkBoxPreferenceStyle">#style/Preference.CheckBoxPreference</item>
<item name="switchPreferenceCompatStyle">#style/Preference.SwitchPreferenceCompat</item>
<item name="dialogPreferenceStyle">#style/Preference.DialogPreference</item>
<item name="editTextPreferenceStyle">#style/Preference.DialogPreference.EditTextPreference</item>
<item name="preferenceFragmentListStyle">#style/PreferenceFragmentList</item>
<item name="android:subtitleTextStyle">#color/dark_gray</item>
</style>
My prefernce xml:
<android.support.v7.preference.PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent">
<android.support.v7.preference.PreferenceCategory
android:key="pref_user_settings"
android:title="#string/pref_group_user">
<android.support.v7.preference.ListPreference
android:defaultValue="Publisher"
android:entries="#array/pref_user_types"
android:entryValues="#array/pref_user_types"
android:key="pref_user_type"
android:title="#string/pref_title_user_type" />
</android.support.v7.preference.PreferenceCategory>
This is how it looks:
The way i solved it out is customing the preference category file.
Solution:
Create a new layout xml file called custom_preference_category:
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#color/gray"
android:paddingTop="8dp"
android:id="#android:id/title" />
Then add this to your styles file:
<style name="Preference.Category">
<item name="android:layout">#layout/custom_preference_category</item>
<item name="android:shouldDisableView">false</item>
<item name="android:selectable">false</item>
</style>
<style name="PreferenceThemeOverlay">
<item name="preferenceScreenStyle">#style/Preference.PreferenceScreen</item>
<item name="preferenceFragmentStyle">#style/PreferenceFragment</item>
<item name="preferenceCategoryStyle">#style/Preference.Category</item>
<item name="preferenceStyle">#style/Preference</item>
<item name="preferenceInformationStyle">#style/Preference.Information</item>
<item name="checkBoxPreferenceStyle">#style/Preference.CheckBoxPreference</item>
<item name="switchPreferenceCompatStyle">#style/Preference.SwitchPreferenceCompat</item>
<item name="dialogPreferenceStyle">#style/Preference.DialogPreference</item>
<item name="editTextPreferenceStyle">#style/Preference.DialogPreference.EditTextPreference
</item>
<item name="preferenceFragmentListStyle">#style/PreferenceFragmentList</item>
</style>
And then use this style in your main app theme:
<item name="preferenceTheme">#style/PreferenceThemeOverlay</item>
I did it a lot of time ago so I'm not sure if this all I've done, so give me a feedback if something is missing.
My menu layout looks like this:
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item android:id="#+id/action_change_pin"
android:title="#string/action_change_pin"
android:textColor="#000000"
android:orderInCategory="100"
app:showAsAction="never" />
<item android:id="#+id/action_logout"
android:title="#string/action_logout"
android:orderInCategory="100"
app:showAsAction="never" />
I want to change these two items' text color to white from black. How can i do that?
I think u need to change the style:
try this :
put this in your theme
<item name="android:itemTextAppearance">#style/myCustomMenuTextApearance</item>
and in your styles.xml:
<style name="myCustomMenuTextApearance" parent="#android:style/TextAppearance.Widget.IconMenu.Item">
<item name="android:textColor">#color/your_color</item>
</style>
should help u out
In your theme.xml
<style name="LightTheme" parent="#style/Theme.AppCompat.Light">
<item name="actionMenuTextColor">#FFF</item>
<item name="android:actionMenuTextColor">#FFF</item>
</style>
Try this:
<style name="ThemeName" parent="#style/Theme.Sherlock.Light">
<item name="actionMenuTextColor">#color/white</item>
<item name="android:actionMenuTextColor">#color/white</item>
</style>