android popup menu text color (AppCompat) - android

I need to change text color of a popuo menu but I don't find any way for do this, I can change background of popmenu but not the text, I edit the style.xml in this way:
<style name="AppBaseTheme" parent="Theme.AppCompat.Light">
<!-- API 14 theme customizations can go here. -->
<item name="popupMenuStyle">#style/MyPopupMenu</item>
<item name="android:textAppearanceLargePopupMenu">#style/myPopupMenuTextAppearanceLarge</item>
<item name="android:textAppearanceSmallPopupMenu">#style/myPopupMenuTextAppearanceSmall</item>
</style>
<style name="MyPopupMenu" parent="#style/Widget.AppCompat.PopupMenu">
<item name="android:popupBackground">#0F213F</item>
</style>
<style name="myPopupMenuTextAppearanceSmall" parent="#style/TextAppearance.AppCompat.Base.Widget.PopupMenu.Small">
<item name="android:textColor">#ffffff</item>
</style>
<style name="myPopupMenuTextAppearanceLarge" parent="#style/TextAppearance.AppCompat.Base.Widget.PopupMenu.Large">
<item name="android:textColor">#ffffff</item>
</style>
where is the mistake?

In styles.xml
<style name="itemTextStyle.AppTheme" parent="#android:style/TextAppearance.Widget.IconMenu.Item">
<item name="android:textColor">#drawable/color_item_popup</item>
<item name="android:textSize">#dimen/text_content</item>
</style>
and add in AppTheme
<item name="android:itemTextAppearance">#style/itemTextStyle.AppTheme</item>
color_item_popup.xml
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" android:color="#color/primary_text"/>
<item android:state_focused="true" android:color="#color/primary_text"/>
<item android:color="#color/secondary_text"/>
</selector>

<item name="textAppearanceLargePopupMenu">#style/TextAppearance.AppCompat.Light.Widget.PopupMenu.Large</item>
<item name="textAppearanceSmallPopupMenu">#style/TextAppearance.AppCompat.Light.Widget.PopupMenu.Small</item>
I think that you are using TextAppearance.AppCompat.Base.Widget.PopupMenu. Here is the error, you are using another parent that doesn´t response the current style.
You have to use:
TextAppearance.AppCompat.Light.Widget.PopupMenu.

In styles.xml:
<style name="PopupMenu" parent="Widget.AppCompat.PopupMenu.Overflow">
<item name="android:popupBackground">#color/white</item>
</style>
In java:
Context wrapper = new ContextThemeWrapper(getContext(), R.style.PopupMenu);
final PopupMenu popupMenu = new PopupMenu(wrapper, view);

//In Main Style
<item name="popupMenuStyle">#style/popupMenuStyle</item>
<item name="android:textAppearanceSmallPopupMenu">#style/myPopupMenuTextAppearanceSmall</item>
<item name="android:textAppearanceLargePopupMenu">#style/myPopupMenuTextAppearanceLarge</item>
//In Define part
<style name="popupMenuStyle" parent="Widget.AppCompat.PopupMenu">
<item name="android:popupBackground">#drawable/popup_bg</item>
<item name="android:textColor">#ffffff</item>
</style>
<style name="myPopupMenuTextAppearanceSmall" parent="#style/TextAppearance.AppCompat.Widget.PopupMenu.Small">
<item name="android:textColor">#ffffff</item>
</style>
<style name="myPopupMenuTextAppearanceLarge" parent="#style/TextAppearance.AppCompat.Widget.PopupMenu.Large">
<item name="android:textColor">#ffffff</item>
</style>
//you may use this background
//popup_bg.xml
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient
android:angle="135"
android:centerColor="#c8232323"
android:endColor="#c80d0d0d"
android:startColor="#c8434242"
android:type="linear" />
</shape>

Related

Changing textstyle of popupmenu in themes.xml doesn't work

I would like to change the textsize of popupmenu,so I try it in styles.xml and themes.xml,but the textsize seems to be override by android:textViewStyle.If I delete android:textViewStyle in my themes.xml,the textsize of popupmenu works.Is there something wrong in my code?
styles.xml
<style name="mytextviewstyle" parent="Widget.MaterialComponents.TextView">
<item name="android:gravity">center_vertical</item>
<item name="android:textAppearance">#dimen/body_text_appearance</item>
<item name="minHeight">#dimen/body_text_minHeight</item>
<item name="android:textSize">32sp</item>
</style>
<style name="mypopmenustyle" parent="Widget.MaterialComponents.PopupMenu.Overflow">
<item name="android:textSize">#16sp</item>
<item name="android:textColor">#color/white</item>
<item name="android:popupBackground">?attr/colorPrimary</item>
</style>
themes.xml
<item name="android:textViewStyle">#style/mytextviewstyle</item>
<item name="actionOverflowMenuStyle">#style/mypopmenustyle</item>
By the way,android:buttonStyle and buttonStyle don't work too.Still get the default button.
styles.xml
<style name="mybottonstyle" parent="Widget.MaterialComponents.Button">
<item name="android:gravity">center_vertical</item>
<item name="android:textAppearance">#dimen/body_text_appearance</item>
<item name="android:textSize">#dimen/body_textSize</item>
</style>
themes.xml
<item name="android:buttonStyle">#style/mybottonstyle</item>
<item name="buttonStyle">#style/mybottonstyle</item>

Change DatePicker Text Color

I want to change the text color of DatePicker.
I have tried couple of suggestions found here but nothing has worked for me.
The text color, and the selected background stays the same.
The top header background did changed.
<style name="MyThemeDesign" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">#color/btnColor</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="android:datePickerStyle">#style/MyDatePickerStyle</item>
</style>
<style name="MyDatePickerStyle" parent="#android:style/Widget.Material.Light.DatePicker">
<item name="android:headerBackground">#color/orange</item>
<item name="android:text">#color/white</item>
<item name="android:calendarTextColor">#color/white</item>
<item name="android:dayOfWeekBackground">#color/white</item>
<item name="android:selectedWeekBackgroundColor">#color/colorRed</item>
<item name="android:yearListSelectorColor">#color/colorRed</item>
<item name="android:colorPrimary">#color/white</item>
<item name="android:colorPrimaryDark">#color/white</item>
<item name="android:colorBackgroundCacheHint">#color/colorRed</item>
<item name="colorAccent">#color/white</item>
<item name="android:textColorPrimary">#color/white</item>
<item name="android:datePickerMode">calendar</item>
<item name="android:minDate">01/01/2017</item>
</style>
In styles.xml:
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
...
<item name="android:datePickerStyle">#style/MyDatePickerStyle</item>
</style>
<style name="MyDatePickerStyle" parent="#android:style/Widget.DeviceDefault.DatePicker">
<item name="android:headerBackground">#color/red</item>
<item name="android:headerMonthTextAppearance">#style/MyDatePickerTextAppearance</item>
</style>
<style name="MyDatePickerTextAppearance" parent="TextAppearance.AppCompat.Body1">
<item name="android:textColor">#drawable/my_color_state_list</item>
</style>
drawable/my_color_state_list.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Month color -->
<item android:color="#color/yellow" android:state_selected="true"/>
<!-- Year color -->
<item android:color="#color/purple" />
</selector>
If you also want to control the selected date color, then add this theme to style.xml:
<style name="MyDatePickerTheme" parent="AppTheme">
<item name="colorAccent">#color/blue</item>
</style>
In layout:
<DatePicker
android:theme="#style/MyDatePickerTheme"
.../>
Result:

Parent style for TextView style with AppCompat usage

What parent style should I use if I want to set global textViewStyle and maintain backward compatibility with AppCompat? I can't find something like Widget.AppCompat.TextView :
<style name="Base_AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:textViewStyle">#style/GlobalTextViewStyle</item>
</style>
<style name="GlobalTextViewStyle" parent="?????">
<item name="android:textAppearance">#style/TextAppearance.AppCompat.Medium</item>
</style>
You just need to extend TextAppearance.AppCompat style overriding necessary values:
<style name="Base_AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:textAppearance">#style/MyTextAppearance</item>
</style>
<style name="MyTextAppearance" parent="TextAppearance.AppCompat">
<item name="android:textColor">?android:textColorPrimary</item>
<item name="android:textColorHint">?android:textColorHint</item>
<item name="android:textColorHighlight">?android:textColorHighlight</item>
<item name="android:textColorLink">?android:textColorLink</item>
<item name="android:textSize">#dimen/abc_text_size_body_1_material</item>
<item name="textColor">?textColorPrimary</item>
<item name="textColorHighlight">?textColorHighlight</item>
<item name="textColorHint">?textColorHint</item>
<item name="textColorLink">?textColorLink</item>
<item name="textSize">16sp</item>
<item name="textStyle">normal</item>
</style>
If you want to set this style for all your TextView's in your app, you can do something like this:
<resources>
<style name="YourTheme" parent="android:YourParentThTheme">
<item name="android:textViewStyle">#style/GlobalTextViewStyle </item>
</style>
<style name="GlobalTextViewStyle" parent="android:Widget.TextView">
<item name="android:textColor">#FF000</item>
<item name="android:textStyle">bold</item>
</style>
</resources>
<style name="normal_text_white" parent="#android:style/TextAppearance.Medium">
<item name="android:textColor">#color/white_color</item>
<item name="android:textSize">#dimen/small_text_size</item>
<item name="android:textColorHint">#color/hint_color</item>
</style>
We can try this as well for AppCompat widget.
<style name="TitleStyle" parent="TextAppearance.AppCompat">
<item name="android:gravity">center_horizontal</item>
<item name="android:textColor">#android:color/black</item>
<item name="android:textSize">26sp</item>
</style>

Change ActionBarTab line between items

I am working on Android project, what I can't change is line between Tab items. Now it's light white / gray, but I want to make it black. I've tried to change style ActionBar.Solid.A with background to black, but it didn't solve the problem. Before I ask question I've check several similar problems, but didn't find solution...
Theme Style
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="Theme.A" parent="#android:style/Theme.Holo.Light.DarkActionBar">
<item name="android:actionBarItemBackground">#drawable/selectable_background_A</item>
<item name="android:popupMenuStyle">#style/PopupMenu.A</item>
<item name="android:dropDownListViewStyle">#style/DropDownListView.A</item>
<item name="android:actionBarTabStyle">#style/ActionBarTabStyle.A</item>
<item name="android:actionDropDownStyle">#style/DropDownNav.A</item>
<item name="android:actionBarStyle">#style/ActionBar.Solid.A</item>
<item name="android:actionModeBackground">#drawable/cab_background_top_A</item>
<item name="android:actionModeSplitBackground">#drawable/cab_background_bottom_A</item>
<item name="android:actionModeCloseButtonStyle">#style/ActionButton.CloseMode.A</item>
<!--<item name="android:actionOverflowButtonStyle">#style/Widget.ActionButton.Overflow</item>-->
<!-- Light.DarkActionBar specific -->
<item name="android:actionBarWidgetTheme">#style/Theme.A.Widget</item>
</style>
<style name="ActionBar.Solid.A" parent="#android:style/Widget.Holo.Light.ActionBar.Solid.Inverse">
<item name="android:titleTextStyle">#style/Theme.A.TitleTextStyle</item>
<item name="android:background">#drawable/ab_solid_A</item>
<item name="android:backgroundStacked">#drawable/ab_stacked_solid_A</item>
<item name="android:backgroundSplit">#drawable/ab_bottom_solid_A</item>
<item name="android:progressBarStyle">#style/ProgressBar.A</item>
</style>
<style name="ActionBar.Transparent.A" parent="#android:style/Widget.Holo.ActionBar">
<item name="android:background">#drawable/ab_transparent_A</item>
<item name="android:progressBarStyle">#style/ProgressBar.A</item>
</style>
<style name="PopupMenu.A" parent="#android:style/Widget.Holo.ListPopupWindow">
<item name="android:popupBackground">#drawable/menu_dropdown_panel_A</item>
</style>
<style name="DropDownListView.A" parent="#android:style/Widget.Holo.ListView.DropDown">
<item name="android:listSelector">#drawable/selectable_background_A</item>
<item name="android:textColor">#color/main_white_color</item>
</style>
<style name="ActionBarTabStyle.A" parent="#android:style/Widget.Holo.ActionBar.TabView">
<item name="android:background">#drawable/tab_indicator_ab_A</item>
</style>
<style name="DropDownNav.A" parent="#android:style/Widget.Holo.Spinner">
<item name="android:background">#drawable/spinner_background_ab_A</item>
<item name="android:popupBackground">#drawable/menu_dropdown_panel_A</item>
<item name="android:dropDownSelector">#drawable/selectable_background_A</item>
</style>
<style name="DropDownSpinner.A" parent="#android:style/Widget.Holo.Light.Spinner">
<item name="android:popupBackground">#drawable/menu_dropdown_panel_spinner</item>
</style>
<style name="ProgressBar.A" parent="#android:style/Widget.Holo.ProgressBar.Horizontal">
<item name="android:progressDrawable">#drawable/progress_horizontal_A</item>
</style>
<style name="ActionButton.CloseMode.A" parent="#android:style/Widget.Holo.ActionButton.CloseMode">
<item name="android:background">#drawable/btn_cab_done_A</item>
</style>
<!-- this style is only referenced in a Light.DarkActionBar based theme -->
<style name="Theme.A.Widget" parent="#android:style/Theme.Holo">
<item name="android:popupMenuStyle">#style/PopupMenu.A</item>
<item name="android:dropDownListViewStyle">#style/DropDownListView.A</item>
<item name="android:textColor">#color/main_white_color</item>
</style>
<!-- ActionBar TitleTextStyle styles -->
<style name="Theme.A.TitleTextStyle" parent="#android:style/TextAppearance.Holo.Widget.ActionBar.Title">
<item name="android:textColor">#color/main_white_color</item>
</style>
<!-- ActionBar SettingIcon style -->
<style name="Widget.ActionButton.Overflow" parent="#android:style/Widget.Holo.ActionButton.Overflow">
<item name="android:src">#drawable/ic_dots</item>
</style>
</resources>
What you want to change is the ActionBarTab divider color. You can do it like this:
Inside ActionBarTabStyle.A definition, add:
<item name="android:actionBarDivider">#drawable/tab_divider</item>
The tab_divider drawable is an XML file as well:
<?xml version="1.0" encoding="utf-8"?>
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:fromDegrees="90"
android:toDegrees="90" >
<shape android:shape="line" >
<stroke
android:dashWidth="3dp"
android:width="4dp"
android:color="#android:color/black" />
</shape>
</rotate>
Edit: An alternative solution is simply changing your Theme.A theme directly, adding:
<item name="actionBarDivider">#android:color/black</item>
Note that the android: prefix is not being used.

How can I set the background color of the overflow menu in Android?

I am trying to set a custom background color to the overflow menu. However, I am unable to do so. This is what I tried:
<resources>
<style name="TranslucentTheme" parent="android:Theme.Holo.Light.DarkActionBar">
<item name="android:actionBarStyle">#style/TranslucentActionBar</item>
<item name="android:windowActionBarOverlay">true</item>
<item name="android:windowTranslucentStatus">true</item>
<item name="android:windowTranslucentNavigation">true</item>
<item name="android:windowBackground">#android:color/transparent</item>
<item name="android:popupMenuStyle">#style/PopupMenu</item>
</style>
<style name="PopupMenu" parent="#android:Widget.Holo.Light.PopupWindow">
<item name="android:popupBackground">#color/transparent_black</item>
</style>
<style name="TranslucentActionBar" parent="android:Widget.Holo.Light.ActionBar.Solid.Inverse">
<item name="android:background">#null</item>
<item name="android:logo">#drawable/actionbar_logo_space</item>
</style>
</resources>
What am I doing wrong?
Try this:
1) Add style to DropDownListView:
<style name="OdnakoDropDownListView" parent="#android:Widget.Holo.ListView.DropDown">
<item name="android:listSelector">#drawable/selectable_background</item>
<item name="android:background">#android:color/black</item>
<item name="actionMenuTextColor">#android:color/white</item>
</style>
2) Create selectable_background.xml in yours /res/drawable
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#drawable/list_focused" android:state_focused="true" android:state_pressed="false"/>
<item android:drawable="#drawable/ic_launcher" android:state_pressed="true"/>
<item android:drawable="#android:color/blue"/>
</selector>
3) Add item to yours theme:
<style name="TranslucentTheme" parent="android:Theme.Holo.Light.DarkActionBar">
<!-- other attributes-->
<item name="android:dropDownListViewStyle">#style/OdnakoDropDownListView</item>
</style>

Categories

Resources