I am working on an app that uses a theme that extends #style/Theme.AppCompat.Light.DarkActionBar.
On one of my activities, there is an Action Bar icon that shows three options with radiobuttons (here's an extract from the menu XML file):
<item
android:icon="#drawable/ic_action_filter_white"
android:showAsAction="always"
android:title=""
preparatest:showAsAction="always">
<menu>
<group android:checkableBehavior="single" >
<item
android:id="#+id/menu_filter_all"
android:title="#string/history_list_filter_all"
android:checked="true"/>
<item
android:id="#+id/menu_filter_pending"
android:title="#string/history_list_filter_pending"/>
<item
android:id="#+id/menu_filter_finished"
android:title="#string/history_list_filter_finished"/>
</group>
</menu>
</item>
I want to give these radiobuttons a custom style, but I don't know where to do it. On my styles.xml file I have defined the custom style as
<style name="RadioButtonPTGreenTheme" parent="android:Widget.CompoundButton.RadioButton">
<item name="android:button">#drawable/ptgreentheme_btn_radio_holo_light</item>
</style>
and tried using all these four options, but to no avail:
<item name="android:radioButtonStyle">#style/RadioButtonPTGreenTheme</item>
<item name="android:listChoiceIndicatorSingle">#style/RadioButtonPTGreenTheme</item>
<item name="android:radioButtonStyle">#drawable/ptgreentheme_btn_radio_holo_light</item>
<item name="android:listChoiceIndicatorSingle">#drawable/ptgreentheme_btn_radio_holo_light</item>
Does anyone know how to do this? Thanks!
See this blog post for a way to do it.
Long story short, android:actionBarWidgetTheme is used to style elements that depend on the Action Bar, so the android:radioButtonStyle should be put inside a style for actionBarWidgetTheme:
<style name="MyTheme" parent="#android:style/Theme.Holo.Light.DarkActionBar">
<item name="android:actionBarWidgetTheme">#style/MyActionBarWidgetTheme</item>
</style>
<style name="MyActionBarWidgetTheme" parent="#android:style/Theme.Holo">
<item name="android:radioButtonStyle">#style/MyRadioButtonStyle</item>
</style>
Related
Hey everyone I am dealing with a small problem with Popup menu. Honestly I dont know where is the problem, I tried to search the internet if I can find any answers but unfortunatelly I cant. So..
I created a custom toolbar and set the activity to no actionbar. Then I created a popUp menu in this toolbar. First I tried to change the icon of a menu via styles and it worked. But then I wanted to change the background and text color of a menu items.
This is the code I have in my design tab of the menu item:
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item android:id="#+id/fitItem1"
android:title="Item 1"
app:showAsAction="never" />
<item android:id="#+id/fitItem2"
android:title="Item 2"
app:showAsAction="never"/>
<item android:id="#+id/fitItem3"
android:title="Item 3"
app:showAsAction="never"/>
And even in the design menu it looked like this:
But when you start the app it looks by default (white background, black text)
So I thought that is it set somewhere in styles but there is nothing like that and every guide I tried to follow had no effect. Except style name="MyPopBackground" which actully changes the background.
<resources>
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="android:actionOverflowButtonStyle">#style/MyActionButtonOverflow</item>
<item name="android:itemTextAppearance">#style/MyApp.PopupMenu</item>
<item name="android:popupBackground">#style/MyPopBackground</item>
</style>
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<style name="MyActionButtonOverflow" parent="android:Widget.Holo.Light.ActionButton.Overflow">
<item name="android:src">#drawable/triple_dot_icon</item>
</style>
<style name="MyApp.PopupMenu" parent="android:style/TextAppearance.Holo.Widget.ActionBar.Title">
<item name="android:textColor">#color/colorLightGrey</item>
</style>
<style name="MyPopBackground" parent="android:style/Widget.Holo.Light.ListPopupWindow">
<item name="android:popupBackground">#color/colorGrey</item>
</style>
</resources>
There might be some useless styles but since I didnt know where is the prob. I left them there. My goal is to make that menu look like that one the image showed before.
I would be glad for any help, thanks for help.
Add popupMenu style to your AppTheme
<style name="AppTheme" parent="android:Theme.Light">
<item name="android:popupMenuStyle">#style/PopupMenu</item>
</style>
<style name="PopupMenu" parent="#android:style/Widget.PopupMenu">
<item name="android:popupBackground">#android:color/white</item>
</style>
then at mainifest.xml
<application
android:theme="#style/AppTheme" >
</application>
In style AppTheme, You add <item name="android:itemBackground">#color/colorMenu</item>
How to change the text color of submenu in Android? I customize the application theme and override the relative attributes, but it still doesn't work. My menu has two submenus, which are initially hidden, when clicked, it shows. However, the style of submenus can't be modified, while the title of action bar can. This question bothers me all the day, I almost try every ways I find.
This is my code!
menu.xml
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
tools:context="com.example.classsignin.MainActivity" >
<item
android:id="#+id/action_overflow"
android:title="分享"
android:icon="#drawable/drop_select"
android:showAsAction="always"
>
<menu >
<item
android:id="#+id/absent"
android:title="请假"
android:icon="#drawable/absent"
/>
<item
android:id="#+id/refresh"
android:title="刷新课程"
android:icon="#drawable/refresh"
/>
</menu>
</item>
styles.xml
<style name="CustomTheme" parent="#android:style/Theme.Holo.Light">
<item name="android:actionBarStyle">#style/MyActionBarTheme</item>
<item name="android:actionMenuTextAppearance">#style/MyActionBarMenu</item>
<item name="android:actionMenuTextColor">#color/blue</item>
<item name="android:homeAsUpIndicator">#drawable/back</item>
<item name="android:spinnerItemStyle">#style/MySpinnerItem</item>
</style>
<style name="MyActionBarTheme" parent="#android:style/Widget.Holo.Light.ActionBar">
<item name="android:background">#color/white</item>
<item name="android:titleTextStyle">#style/MyActionBarTitle</item>
</style>
<style name="MyActionBarTitle" parent="#android:style/TextAppearance.Holo.Widget.ActionBar.Title">
<item name="android:textSize">16sp</item>
<item name="android:textColor">#color/blue</item>
</style>
<style name="MyActionBarMenu" parent="#android:style/TextAppearance.Holo.Widget.ActionBar.Menu">
<item name="android:textSize">16sp</item>
<item name="android:textColor">#color/blue</item>
</style>
<style name="MySpinnerItem" parent="#android:style/Widget.Holo.TextView.SpinnerItem">
<item name="android:textAppearance">#style/MyTextAppearance</item>
</style>
<style name="MyTextAppearance" parent="#android:style/TextAppearance.Holo.Widget.TextView.SpinnerItem">
<item name="android:textColor">#color/blue</item>
</style>
Essentially you will want to customise your MenuItem's style by having the android:itemBackground attribute overridden with your custom color/drawable selector in your style.xml and as well a vtextColor` attribute to override.
In case your menu has also submenu's, then you will want as well to style the header title of the submenu, which usually is automatically with White background by overriding the attribute actionBarPopupTheme with your custom style.
style.xml
<resources>
<style name="AppTheme" parent="Theme.AppCompat.DayNight.DarkActionBar">
<item name="android:itemBackground">#drawable/menu_popup_selector</item>
<item name="actionBarPopupTheme">#style/SubmenuHeaderStyle</item>
</style>
<style name="SubmenuHeaderStyle" parent="ThemeOverlay.AppCompat.Light">
<item name="android:colorBackground">#color/colorPrimary</item>
<item name="android:textColor">#color/colorAccent</item>
</style>
</resources>
menu_popup_selector.xml
<?xml version="1.0" encoding="utf-8"?>
<selector
xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true">
<color
android:color="#color/colorPrimary"/>
</item>
<item>
<color
android:color="#655611"/>
</item>
</selector>
And you will have something like those screenshots
(1st menu and then the submenu after clicking one item on the 1st menu - the pink header is my submenu header).
Just for you to know when I have the normal menu without submenu would look like this hierarchy views:
<menu>
<item/>
<item/>
<item/>
</menu>
and a menu with submenu as this example of hierarchy views:
<menu>
<item/>
<item/>
<group>
<item>
<menu>
item
item
item
</menu>
</item>
</group>
<item/>
<item/>
</menu>
In the toolbar's dropdown option menu, does anyone know how to add left side check mark in the menu item?
It is similar behavior as to use <group>, but the <group> gives a default radio button in the right side of the menu item. Thanks!
You can use setGroupCheckable()
EDIT-1:
use the following code:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<group android:checkableBehavior="all">
<item android:id="#+id/red"
android:title="#string/red" />
<item android:id="#+id/blue"
android:title="#string/blue" />
</group>
</menu>
The checkableBehavior="all" converts it into checkboxes.
Edit-2:
I had posted the following code somewhere.. Refer to get started on how to customize action bar menu items :
in your style file, place the following:
<style name="MyAppTheme" parent="#android:style/Theme.Holo.Light">
<item name="android:actionBarStyle">#style/MyActionBar</item>
<item name="android:titleTextStyle">#style/MyActionBar.TitleTextStyle
<item name="android:actionMenuTextAppearance">#style/MyActionBar.MenuTextStyle</item>
<item name="android:actionMenuTextColor">#color/action_bar_red</item> </style>
<style name="MyActionBar.TitleTextStyle" parent="android:style/TextAppearance.Holo.Widget.ActionBar.Title"> <item name="android:textColor">#F0F</item> <item name="android:textStyle">bold</item>
<item name="android:textSize">24dip</item> </style>
<style name="MyActionBar.MenuTextStyle" parent="android:style/TextAppearance.Holo.Widget.ActionBar.Menu"> <item name="android:textColor">#F0F</item> <item name="android:textStyle">bold</item>
<item name="android:textSize">24dip</item>
</style>
You can make changes in the above style items to suit your requirements. I have not added separate styling for color though. As you might observe, I am just assigning red color (which I have declared in my colors file) to it. You may change as required.
I want to show a group of options in the menu, and need to change the standard three-lines icon to my own image. How can I achieve this? Group doesn't have an #icon option, unfortunately
menu.xml
<item
android:icon="#drawable/settings">
<group android:menuCategory="container">
<item
android:id="#+id/action_mute"
android:showAsAction="never"
android:title="#string/action_mute"/>
<item
android:id="#+id/action_add"
android:showAsAction="never"
android:title="#string/action_add"/>
<item
android:id="#+id/action_people"
android:showAsAction="never"
android:title="#string/action_people"/>
<item
android:id="#+id/action_more"
android:showAsAction="never"
android:title="#string/action_more"/>
</group>
</item>
It is called overflow button, if you want to change it you need to declare it in your style.xml located in the values folder.
Add this in your style.xml
<style name="Widget.ActionButton.Overflow" parent="#android:style/Widget.Holo.ActionButton.Overflow">
<item name="android:src">#drawable/your_drawable</item>
</style>
after you need to call it from you AppTheme
<style name="AppTheme" parent="//theme of your actionbar">
<item name="android:actionOverflowButtonStyle">#style/Widget.ActionButton.Overflow</item>
</style>
There's been many questions on styling on action bars, but the ones I've found either are relating to styling the tabs, or have answers that don't work for me.
The question is really quite simple. I want to be able to change the text styling (even just colour) of the menu items in the action bar.
I've read this:
http://android-developers.blogspot.com/2011/04/customizing-action-bar.html?utm_source=feedburner&utm_medium=feed&utm_campaign=Feed%3A+blogspot%2FhsDu+%28Android+Developers+Blog%29
And this question:
Style an Action Bar in Android Honeycomb
From which I have put together a test application that I am using to try and get the menu items to change. It uses all the default values for an app created in the eclipse android plugin, except for the following.
A styles file:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="MyAppTheme" parent="#android:style/Theme.Holo.Light">
<item name="android:actionBarStyle">#style/MyActionBar</item>
</style>
<style name="MyActionBar" parent="#android:style/Widget.Holo.ActionBar">
<item name="android:titleTextStyle">#style/MyActionBar.TitleTextStyle</item>
<item name="android:actionMenuTextAppearance">#style/MyActionBar.MenuTextStyle</item>
</style>
<style name="MyActionBar.TitleTextStyle"
parent="android:style/TextAppearance.Holo.Widget.ActionBar.Title">
<item name="android:textColor">#F0F</item>
<item name="android:textStyle">bold</item>
<item name="android:textSize">24dip</item>
</style>
<style name="MyActionBar.MenuTextStyle"
parent="android:style/TextAppearance.Holo.Widget.ActionBar.Title">
<item name="android:textColor">#F0F</item>
<item name="android:textStyle">bold</item>
<item name="android:textSize">24dip</item>
</style>
</resources>
A menu for the action bar:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:showAsAction="always|withText" android:icon="#android:drawable/ic_menu_edit"
android:id="#+id/menu_item1" android:title="menu_item1"></item>
<item android:showAsAction="always|withText" android:icon="#android:drawable/ic_menu_edit"
android:id="#+id/menu_item2" android:title="menu_item2"></item>
</menu>
The main activity:
public class Main extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
/**
* Create the options menu that is shown on the action bar
*/
#Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.main_menu, menu);
return true;
}
}
The application compiles and runs. The styling for the action bar title text works perfectly (is that lovely shade of pink #F0F I've defined). The menu items do not change appear but with default styling (holo light).
What am I doing wrong ?
Instead of having the android:actionMenuTextAppearance item under your action bar style, move it under your app theme.
I know its an old post, but just in case anyone is looking here. I added this to my style.xml and it worked for me.
<!-- This is the main theme parent -->
<style name="MyTabStyle">
<item name="android:actionBarTabTextStyle">#style/MyTabTextStyle</item>
</style>
<style name="MyTabTextStyle" parent="#android:style/Widget.ActionBar.TabText">
<item name="android:textAppearance">#android:style/TextAppearance.Medium</item>
<item name="android:textSize">14sp</item>
<item name="android:textStyle">bold</item>
<item name="android:textColor">#color/pressed_skylogtheme</item>
</style>
You have to change
<style name="MyActionBar.MenuTextStyle"
parent="android:style/TextAppearance.Holo.Widget.ActionBar.Title">
to
<style name="MyActionBar.MenuTextStyle"
parent="android:style/TextAppearance.Holo.Widget.ActionBar.Menu">
as well. This works for me.
I think the code below
<item name="android:actionMenuTextAppearance">#style/MyActionBar.MenuTextStyle</item>
must be in MyAppTheme section.
Chris answer is working for me...
My values-v11/styles.xml file:
<resources>
<style name="LightThemeSelector" parent="android:Theme.Holo.Light.DarkActionBar">
<item name="android:actionBarStyle">#style/ActionBar</item>
<item name="android:editTextBackground">#drawable/edit_text_holo_light</item>
<item name="android:actionMenuTextAppearance">#style/MyActionBar.MenuTextStyle</item>
</style>
<!--sets the point size to the menu item(s) in the upper right of action bar-->
<style name="MyActionBar.MenuTextStyle" parent="android:style/TextAppearance.Holo.Widget.ActionBar.Title">
<item name="android:textSize">25sp</item>
</style>
<!-- sets the background of the actionbar to a PNG file in my drawable folder.
displayOptions unset allow me to NOT SHOW the application icon and application name in the upper left of the action bar-->
<style name="ActionBar" parent="#android:style/Widget.Holo.ActionBar">
<item name="android:background">#drawable/actionbar_background</item>
<item name="android:displayOptions"></item>
</style>
<style name="inputfield" parent="android:Theme.Holo.Light">
<item name="android:textColor">#color/red2</item>
</style>
</resources>
I did this way:
<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="actionMenuTextAppearance">#style/MenuTextAppearance</item>
<item name="android:actionMenuTextAppearance">#style/MenuTextAppearance</item>
<item name="actionMenuTextColor">#color/colorAccent</item>
</style>
<style name="MenuTextAppearance" >
<item name="android:textAppearance">#android:style/TextAppearance.Large</item>
<item name="android:textSize">20sp</item>
<item name="android:textStyle">bold</item>
</style>
My guess is that you have to also style the views that are generated from the menu information in your onCreateOptionsMenu(). The styling you applied so far is working, but I doubt that the menu items, when rendered with text use a style that is the same as the title part of the ActionBar.
You may want to look at Menu.getActionView() to get the view for the menu action and then adjust it accordingly.
BottomNavigationView navigation = (BottomNavigationView) findViewById(R.id.navigation);
TextView textView = (TextView) navigation.findViewById(R.id.navigation_home).findViewById(R.id.smallLabel);
textView.setTypeface(Typeface.DEFAULT_BOLD);
textView = (TextView) navigation.findViewById(R.id.navigation_home).findViewById(R.id.largeLabel);
textView.setTypeface(Typeface.DEFAULT_BOLD);