Android AppCompat, how to remove padding between action bar buttons? - android

In AppCompat, there is a 12dip padding on both sides of the action buttons. I want to make it 0dip. I have read a few posts and tried for hours, no success. Here is the content of my style.xml:
<style name="AppBaseTheme" parent="Theme.AppCompat.Light">
</style>
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
<item name="actionBarStyle">#style/CustomActionBarStyle</item>
</style>
<style name="CustomActionBarStyle" parent="Widget.AppCompat.Light.ActionBar">
<item name="actionButtonStyle">#style/CustomActionButtonStyle</item>
</style>
<style name="CustomActionButtonStyle" parent="Widget.AppCompat.Light.ActionButton">
<item name="android:paddingLeft">0dp</item>
<item name="android:paddingRight">0dp</item>
</style>

In my case (Sony Xperia Z3 Tablet Compact android 5.1.1) was the only solution to add:
<item name="android:padding">0dp</item>
into CustomActionButtonStyle

Related

Change text size of actionbar item in android

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.

How to align the Action bar Tab text in android

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.

Action bar menu font color change using appcompat

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>

How to change the background color of the action bar in Android?

I was working hard to achieve this but I had no luck. What I tried to do is to change the background color from the style that I attached in my main style tag. This is my code:
<resources>
<style name="AppBaseTheme" parent="#android:style/Theme.Holo.Light">
<item name="android:actionBarStyle">#style/MyActionBar</item>
<item ></item>
</style>
<style name="MyActionBar" parent="#android:style/Widget.Holo.Light.ActionBar">
<item name="android:background">#2E495E</item>
</style>
Still nothing changed.
I get this in my application:
http://i.imgur.com/m1MrGwk.png
I had the same issue and it's probably the same problem you were having. Notice the docs say the following:
each style property that you declare must be declared twice..
So my issue was I declared it for 2.1 and up, but not for 3.0 and greater so my Galaxy S4 of course could not see any changes to the colours I was making.
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light">
<item name="android:actionBarStyle">#style/MyActionBar</item>
<!--Support Library compatibility-->
<item name="actionBarStyle">#style/MyActionBar</item>
</style>
<!-- ActionBar styles -->
<style name="MyActionBar"
parent="#style/Widget.AppCompat.Light.ActionBar">
<item name="android:background">#color/green</item>
<!--Support Library compatibility-->
<item name="background">#color/green</item>
</style>
<style name="NoActionBar" parent="Theme.AppCompat.Light">
<item name="android:windowNoTitle">true</item>
</style>
Is this the only style.xml you have? Else check if you are modifying
for the right API

Common styles for v10 and v11+?

I'm using the v7 support library in order to have an ActionBar on API Level 10+ (that's Android 2.3.3+). Now, I want to customize the look a bit, so I added an application theme. Excerpt of my values/styles.xml:
<style name="AppTheme" parent="Theme.AppCompat.Light">
<item name="actionBarStyle">#style/ActionBarStyle</item>
</style>
<style name="ActionBarStyle" parent="#style/Widget.AppCompat.ActionBar">
<item name="background">#drawable/bg_actionbar</item>
</style>
This works fine on Android 2.3.3, where the compat stuff is used. However, on Android 4.3 on an N4 (or an emulator), the styles are not applied. If I change the styles.xml file to:
<style name="AppTheme" parent="Theme.AppCompat.Light">
<item name="android:actionBarStyle">#style/ActionBarStyle</item>
</style>
<style name="ActionBarStyle" parent="#style/Widget.AppCompat.ActionBar">
<item name="android:background">#drawable/bg_actionbar</item>
</style>
(notice the added android: prefix) it works on 4.3, but doesn't on 2.3 (styles not applied).
Is there any way I can get around this without specifying each <item> twice, once with the prefix and once without?
There is a perfect example on the google docs site:
http://developer.android.com/guide/topics/ui/actionbar.html#StyleExample
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- the theme applied to the application or activity -->
<style name="CustomActionBarTheme"
parent="#style/Theme.AppCompat.Light">
<item name="android:actionBarStyle">#style/MyActionBar</item>
<item name="android:actionBarTabTextStyle">#style/TabTextStyle</item>
<item name="android:actionMenuTextColor">#color/actionbar_text</item>
<!-- Support library compatibility -->
<item name="actionBarStyle">#style/MyActionBar</item>
<item name="actionBarTabTextStyle">#style/TabTextStyle</item>
<item name="actionMenuTextColor">#color/actionbar_text</item>
</style>
<!-- general styles for the action bar -->
<style name="MyActionBar"
parent="#style/Widget.AppCompat.ActionBar">
<item name="android:titleTextStyle">#style/TitleTextStyle</item>
<item name="android:background">#drawable/actionbar_background</item>
<item name="android:backgroundStacked">#drawable/actionbar_background</item>
<item name="android:backgroundSplit">#drawable/actionbar_background</item>
<!-- Support library compatibility -->
<item name="titleTextStyle">#style/TitleTextStyle</item>
<item name="background">#drawable/actionbar_background</item>
<item name="backgroundStacked">#drawable/actionbar_background</item>
<item name="backgroundSplit">#drawable/actionbar_background</item>
</style>
<!-- action bar title text -->
<style name="TitleTextStyle"
parent="#style/TextAppearance.AppCompat.Widget.ActionBar.Title">
<item name="android:textColor">#color/actionbar_text</item>
</style>
<!-- action bar tab text -->
<style name="TabTextStyle"
parent="#style/Widget.AppCompat.ActionBar.TabText">
<item name="android:textColor">#color/actionbar_text</item>
</style>
</resources>
Is there any way I can get around this without specifying each <item>
twice, once with the prefix and once without?
Another way would be to create version specific res/values-XX folders.
Since the divide is version 10 and versions 10+, you can create res/values-v10/styles.xml containing:
<style name="AppTheme" parent="Theme.AppCompat.Light">
<item name="actionBarStyle">#style/ActionBarStyle</item>
</style>
<style name="ActionBarStyle" parent="#style/Widget.AppCompat.ActionBar">
<item name="background">#drawable/bg_actionbar</item>
</style>
Let versions 10+ deal with the default res/values/styles.xml:
<style name="AppTheme" parent="Theme.AppCompat.Light">
<item name="android:actionBarStyle">#style/ActionBarStyle</item>
</style>
<style name="ActionBarStyle" parent="#style/Widget.AppCompat.ActionBar">
<item name="android:background">#drawable/bg_actionbar</item>
</style>
Still, it isn't much different from specifying <item></item> twice.
For reference, you can look at the project structure of ActionBarSherlock. That should provide you some pointers.
You can also take a look at: Applying Styles and Themes to the UI. Scroll down to sub-section Select a theme based on platform version.
If I have not misunderstand your issue, you can collapse it together this way
<style name="AppTheme" parent="Theme.AppCompat.Light">
<item name="android:actionBarStyle">#style/ActionBarStyle</item>
<item name="actionBarStyle">#style/ActionBarStyle</item>
</style>
<style name="ActionBarStyle" parent="#style/Widget.AppCompat.ActionBar">
<item name="android:background">#drawable/bg_actionbar</item>
<item name="background">#drawable/bg_actionbar</item>
</style>
In my experience, this way eclipse gives compile time errors every time you change somethings inside styles.xml (due of lint if I remember good), but clean and rebuild make those errors go away.

Categories

Resources