Change text of android menu item - java

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>

Related

Change selected icon color of bottom navigation color, based on App theme (Android)

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>

menuOptions how to change color?

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

Button styling gives weird results

I have a simple Button style, like
<style name="AppTheme.Button" parent="Widget.AppCompat.Button.Colored">
<item name="colorButtonNormal">#color/colorPrimary</item>
<item name="android:textColor">#color/white</item>
</style>
at this point the output is as this
it seems that the style is not applied and the colors are not set correctly. When I change the style to something like this
<style name="AppTheme.Button" parent="Widget.AppCompat.Button.Colored">
<item name="android:background">#color/colorPrimary</item>
<item name="android:textColor">#color/white</item>
</style>
I get something like this
Thw Button looks insane, but the style is applied.
How can I retain the Button shape as shiwn in the first picture and apply my styles correctly?
Ok I've found a way to get the Job done quite promisingly
style.xml
<style name="AppTheme.Button" parent="Widget.AppCompat.Button.Colored">
<item name="android:background">#drawable/btn_ripple</item>
<item name="android:textColor">#color/white</item>
<item name="android:padding">10dp</item>
<item name="android:minWidth">88dp</item>
<item name="android:minHeight">36dp</item>
<item name="android:layout_margin">3dp</item>
<item name="android:elevation">1dp</item>
<item name="android:translationZ">1dp</item>
</style>
and last the btn_ripple.xml is
<?xml version="1.0" encoding="utf-8"?>
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
android:color="#color/btn_press">
<item>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<corners android:radius="2dp" />
<solid android:color="#color/colorPrimary" />
</shape>
</item>
</ripple>
and the result is
Regards
I think the problem may be located in the parent.
<style name="AppTheme.Button" parent="Widget.AppCompat.Button.Colored">
I belive the second snippet sets the button style, overriding the parent. Try to remove the parent, and see what happens.
<style name="AppTheme.Button">
<item name="android:background">#color/colorPrimary</item>
<item name="android:textColor">#color/white</item>
</style>

Android - support.v7.PreferenceCategory fill the whole screen

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.

Android change popup menu text color

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>

Categories

Resources