I want to change text size of action bar item.
here is my style.xml:
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="android:actionMenuTextAppearance">#style/menu_text</item>
<!-- Customize your theme here. -->
</style>
<style name="menu_text">
<item name="android:textSize">20sp</item>
</style>
this works on android 5 but on android 4 the text size is default and does not change.
in my Project folder res/styles AppTheme has a comment as below,
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
So you can do it with your app Theme. I have done it via below code,
<style name="Theme.YourTheme" parent="android:style/Theme">
<item name="android:actionBarStyle">#style/Theme.YourTheme.Styled.ActionBar</item>
</style>
<style name="Theme.YourTheme.Styled.ActionBar">
<item name="android:titleTextStyle">#style/Theme.Viadeo.Styled.YourTheme.TitleTextStyle</item>
</style>
<style name="Theme.YourTheme.Styled.ActionBar.TitleTextStyle" parent="#android:style/Widget.TextView">
<item name="android:textSize">12dp</item>
</style>
Hope this helps you.
Related
I've been trying real hard to theme SearchView. My min API is sdk 21 too, so I should be able to use the new styling options.
Specifically, I want the in-app-bar text field that appears when I click on the search icon to be theme-able. I want to ultimately make the background white, and the text/cursor either blue or black.
Here is my styles.xml. The last theme is the new SearchTheme I'm working on. The actual values don't matter, they're garbage values I threw in just trying to make a change happen.
<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>
<item name="android:windowBackground">#android:color/white</item>
<item name="android:searchViewStyle">#style/AppTheme.SearchTheme</item>
</style>
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<style name="AppTheme.PreferencesTheme" parent="AppTheme">
<item name="android:windowBackground">#android:color/white</item>
</style>
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar">
<item name="android:windowBackground">#android:color/white</item>
<item name="android:searchViewStyle">#style/AppTheme.SearchTheme</item>
</style>
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light">
<item name="android:windowBackground">#android:color/white</item>
<item name="android:searchViewStyle">#style/AppTheme.SearchTheme</item>
</style>
<style name="AppTheme.SearchTheme" parent="Theme.AppCompat.Light">
<item name="android:closeIcon">#drawable/contacts5icon</item>
<item name="android:voiceIcon">#drawable/contacts5icon</item>
<item name="android:queryBackground">#android:color/black</item>
<item name="android:windowBackground">#android:color/white</item>
</style>
</resources>
I've assigned the AppTheme.SearchTheme to the other main themes that I'm using in my layout. But nothing I do seems to have any effect. The values don't seem to change.
I haven't really messed with Android theming before, so I'm a bit lost.
This should help you get on the right track, per Chris Banes' walk-through for using material design on pre-lollipop androids. For you, in a nutshell: set item property searchViewStyle under your main style with a Widget.AppCompat.SearchView style extension.
You can use the queryBackground item property for altering the text field's background. Other properties are detailed below.
<style name=”Theme.MyTheme” parent=”Theme.AppCompat”>
<item name=”searchViewStyle”>#style/MySearchViewStyle</item>
</style>
<style name=”MySearchViewStyle” parent=”Widget.AppCompat.SearchView”>
<!-- Background for the search query section (e.g. EditText) -->
<item name="queryBackground">...</item>
<!-- Background for the actions section (e.g. voice, submit) -->
<item name="submitBackground">...</item>
<!-- Close button icon -->
<item name="closeIcon">...</item>
<!-- Search button icon -->
<item name="searchIcon">...</item>
<!-- Go/commit button icon -->
<item name="goIcon">...</item>
<!-- Voice search button icon -->
<item name="voiceIcon">...</item>
<!-- Commit icon shown in the query suggestion row -->
<item name="commitIcon">...</item>
<!-- Layout for query suggestion rows -->
<item name="suggestionRowLayout">...</item>
</style>
more here
I've been searching but still am unable to find a way.
How does one change all text button colors (without modifying the android:textColor of other widgets in a scheme?
NB: Does not work
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorButtonNormal">#1bbc9b</item>
<!--<item name="android:textColor">#ffffff</item>-->
<item name="android:buttonStyle">#style/AppTheme.MyButton</item>
</style>
<style name="AppTheme.MyButton" parent="#android:style/TextAppearance">
<item name="android:textColor">#ffffff</item>
</style>
UPDATE: Fix for just altering button color, not entire button style
This worked for me. In the values/styles.xml, configure:
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorButtonNormal">#fcfc00</item>
<!-- more stuff here -->
</style>
You can check out my output below.There you can see, In ANNOUNCEMENT,letter T is placed at bottom.It needs to be align like Gallery and placed in the center.
styles.xml:
<resources>
<style name="AppBaseTheme" parent="android:Theme.Light">
<!--
Theme customizations available in newer API levels can go in
res/values-vXX/styles.xml, while customizations related to
backward-compatibility can go here.
-->
</style>
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
</style>
<style name="GridLayout">
<item name="android:drawSelectorOnTop">true</item>
<item name="android:listSelector">#drawable/photogrid_list_selector</item>
</style>
<style name="CustomRatingBar" parent="#android:style/Widget.RatingBar">
<item name="android:progressDrawable">#drawable/custom_ratingbar</item>
<item name="android:minHeight">20dip</item>
<item name="android:maxHeight">20dip</item>
</style>
<style name="CustomTheme" parent="#android:style/Theme">
<item name="android:tabWidgetStyle">#style/CustomTabWidget</item>
</style>
<style name="CustomTabWidget" parent="#android:style/Widget.TabWidget">
<item name="android:textAppearance">#style/CustomTabWidgetText</item>
</style>
<style name="CustomTabWidgetText"
parent="#android:style/TextAppearance.Widget.TabWidget">
<item name="android:textSize">12sp</item>
<!-- <item name="android:textStyle">bold</item> -->
</style>
</resources>
I doesn't know how to solve these issue.Anybody can help me if you know how to solve these.Thank you.
I just tried it almost two days.But I can't find a solution for
these.After that I think and solve these problem.
Actually I am using an emulator.So that these kind of problems
occurred for me.
Then I try to run these code in Real devices.It seems Action bar
Tab test Announcement align at the centre.Problem solved for me.
I have a contextual action mode, the text color of the action bar menu should be red in color.
I am able to change the text color using
<style name="AppTheme" parent="#style/Theme.AppCompat.Light">
<!-- Setting values in the android namespace affects API levels 14+ -->
<item name="android:actionBarStyle">#style/MyStyledActionBar</item>
</style>
<style name="MyStyledActionBar" parent="#style/Widget.AppCompat.Light.ActionBar">
<!-- Setting values in the android namespace affects API levels 14+ -->
<item name="android:background">#drawable/bg_action_bar</item>
<item name="android:titleTextStyle">#style/MyActionBarTitleText</item>
<item name="android:actionMenuTextAppearance">#style/MyActionBarMenuText</item>
<item name="android:actionMenuTextColor">#style/MyActionBarMenuText</item>
<item name="android:actionOverflowButtonStyle">#style/MyActionButtonOverFlow</item>
</style>
<style name="MyActionBarTitleText" parent="#style/TextAppearance.AppCompat.Widget.ActionBar.Title">
<item name="android:textColor">#color/font_half_white</item>
</style>
<style name="MyActionBarMenuText" parent="#style/TextAppearance.AppCompat.Widget.ActionBar.Menu">
<item name="android:textColor">#color/font_half_white</item>
</style>
<style name="MyActionButtonOverFlow" parent="#style/Widget.AppCompat.Light.Base.ActionButton.Overflow">
<item name="android:src">#drawable/ic_action_search</item>
</style>
It works in android 2.3, 4.1. but when i run the same in android 4.4. It shows the default black color
Can anyone please let me know, what is the issue.
Thanks in advance.
Maybe it is not the cleanest way to do this but to change the color of my action bar text I use HTML code in the java classe like this:
getSupportActionBar().setTitle(Html.fromHtml("<font color='#FF0000'>"+Your Title+"</font>"));
Hope it helps!
please use below code its working for me
and still if you have doubt and its not working then tell me
<resources>
<!--
Base application theme for API 14+. This theme completely replaces
AppBaseTheme from BOTH res/values/styles.xml and
res/values-v11/styles.xml on API 14+ devices.
-->
<style name="AppTheme" parent="AppBaseTheme">
<!-- <item name="windowBackground">#color/background_window</item> -->
<!-- <item name="android:actionBarStyle">#style/ActionBarStyle</item> -->
<item name="android:actionBarStyle">#style/MyActionBar</item>
</style>
<style name="MyActionBar" parent="#android:style/Widget.ActionBar">
<item name="android:icon">#drawable/ic_launcher</item>
<item name="android:background">#FF666666</item>
<item name="android:titleTextStyle">#style/MyActionBarTitleText</item>
</style>
<style name="MyActionBarTitleText" parent="#android:style/TextAppearance.Holo.Widget.ActionBar.Title">
<item name="android:textColor">#android:color/holo_blue_bright</item>
</style>
I am trying to change the text color of a action menu item on the action bar. Using app compat. Also the overflow icon doesnt change too. Here is my custom styled styles.xml files.
res/values/styles.xml
<style name="AppTheme" parent="#style/Theme.AppCompat.Light">
<!-- Setting values in the default namespace affects API levels 7-13 -->
<item name="actionBarStyle">#style/MyStyledActionBar</item>
</style>
<style name="MyStyledActionBar" parent="#style/Widget.AppCompat.Light.ActionBar">
<!-- Setting values in the default namespace affects API levels 7-13 -->
<item name="background">#drawable/bg_action_bar</item>
<item name="titleTextStyle">#style/MyActionBarTitleText</item>
<item name="actionMenuTextAppearance">#style/MyActionBarMenuText</item>
<item name="actionMenuTextColor">#style/MyActionBarMenuText</item>
<item name="actionOverflowButtonStyle">#style/MyActionButtonOverFlow</item>
</style>
<style name="MyActionBarTitleText" parent="#style/TextAppearance.AppCompat.Widget.ActionBar.Title">
<item name="android:textColor">#color/font_half_white</item>
</style>
<style name="MyActionBarMenuText" parent="#style/TextAppearance.AppCompat.Widget.ActionBar.Menu">
<item name="android:textColor">#color/font_half_white</item>
</style>
<style name="MyActionButtonOverFlow" parent="#style/Widget.AppCompat.Light.ActionButton.Overflow">
<item name="android:src">#drawable/ic_action_search</item>
</style>
res/values-14/styles.xml
<style name="AppTheme" parent="#style/Theme.AppCompat.Light">
<!-- Setting values in the android namespace affects API levels 14+ -->
<item name="android:actionBarStyle">#style/MyStyledActionBar</item>
</style>
<style name="MyStyledActionBar" parent="#style/Widget.AppCompat.Light.ActionBar">
<!-- Setting values in the android namespace affects API levels 14+ -->
<item name="android:background">#drawable/bg_action_bar</item>
<item name="android:titleTextStyle">#style/MyActionBarTitleText</item>
<item name="android:actionMenuTextAppearance">#style/MyActionBarMenuText</item>
<item name="android:actionMenuTextColor">#style/MyActionBarMenuText</item>
<item name="android:actionOverflowButtonStyle">#style/MyActionButtonOverFlow</item>
</style>
<style name="MyActionBarTitleText" parent="#style/TextAppearance.AppCompat.Widget.ActionBar.Title">
<item name="android:textColor">#color/font_half_white</item>
</style>
<style name="MyActionBarMenuText" parent="#style/TextAppearance.AppCompat.Widget.ActionBar.Menu">
<item name="android:textColor">#color/font_half_white</item>
</style>
<style name="MyActionButtonOverFlow" parent="#style/Widget.AppCompat.Light.Base.ActionButton.Overflow">
<item name="android:src">#drawable/ic_action_search</item>
</style>
res/colors.xml
#F3F3F3
The text color still black doesnt change to white. Has anybody successfully changed the action menu text color. Please suggest some insights. I am testing on 4.4 Nexus5 device.
Use
<item name="android:actionMenuTextColor">#color/font_half_white</item>
// added style directly
Instead of
<item name="android:actionMenuTextColor">#style/MyActionButtonStyle</item>
in res/values-14/styles.xml
In res/values/styles.xml
<item name="actionMenuTextColor">#color/font_half_white</item>
I used a Red Color for testing. See the Action menu Item Home that is red in the snap
Edit:
Full Code
In res/values-14/styles.xml
<resources>
<!--
Base application theme for API 14+. This theme completely replaces
AppBaseTheme from BOTH res/values/styles.xml and
res/values-v11/styles.xml on API 14+ devices.
-->
<style name="AppBaseTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- API 14 theme customizations can go here. -->
<item name="android:actionMenuTextColor">#color/red</item>
</style>
</resources>
Then in res/values/stles.xml
<resources>
<style name="AppBaseTheme" parent="Theme.AppCompat.Light">
<!-- API 11 theme customizations can go here. -->
<item name="actionMenuTextColor">#color/red</item>
</style>
</resources>
In manifest
android:theme="#style/AppBaseTheme" >
Another snap
You can use this to change the text of the Action Bar irrespective of your appcompat version.Give the desired color's hex code and add this in the onCreate().
actionBar.setTitle(Html.fromHtml("<font color='#ff0000'>Some Title</font>"));
Check that in your layout xml file you don't have an android:theme attribute specified for your <Toolbar>, which would have priority over the main theme
Override your actionBarStyle attribute as pointed out everywhere over the internets.