2

I am Using Overlay Action Bar By Using the Following Style to my Activity

style.xml

    <style name="CustomActionBarTheme" parent="@style/Theme.AppCompat" >
    <item name="windowActionBarOverlay">true</item>
    <item name="android:background">#00f3ead8</item>
    <item name="android:windowBackground">@drawable/logo1024</item>
</style>

I have only one menu item that is to be displayed Always

menu.xml

<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:yourapp="http://schemas.android.com/apk/res-auto">
<item
    android:id="@+id/menusettings"
    android:orderInCategory="100"
    android:icon="@drawable/settings"
    android:title="Menu"
    yourapp:showAsAction="always"
    />
  <menu>

The Icon i.e the settings.png is getting padded by 8dp But I want 0 padding on the top and bottom so that it covers the Entire Actionbar

Please Help me out in deep trouble very close to the deadline of the project Thanks in advance

user990967
  • 444
  • 1
  • 6
  • 20
  • I have Tried android:paddingTop="0dp" and android:paddingBottom="0dp" in the tag of menu.xml file but no use – user990967 Oct 01 '13 at 06:08
  • You may want to consider using a custom `android:actionLayout` to visualize the action item. That will allow you to fully control its styling, including the padding. [See here for an example](http://stackoverflow.com/a/17735176/1029225). – MH. Oct 01 '13 at 06:28
  • @MH I am Using Appcompat Actionbar What is the Style I should use ? for the actionLayout style – user990967 Oct 01 '13 at 07:18
  • I have modified the code as per your link like this – user990967 Oct 01 '13 at 07:21
  • I have modified the code as per your link like this `code` and the layout file like dis `code` but not working !! – user990967 Oct 01 '13 at 07:30
  • You may have to override the left and right padding too - from the top of my head I can't recall what attributes the `ActionButton` style sets. Or, perhaps even beter, don't apply a style and start from there. – MH. Oct 01 '13 at 07:34
  • It is not showing the image at all when i say that its not working @MH and also it is not showing the submenu when it is clicked – user990967 Oct 01 '13 at 07:43

2 Answers2

3

One year later... Removing padding on v7.Toolbar's action buttons is still challenging. After a lot of experimentation here is a working solution, tested on API 15 and up (theoretically should be working > API 7). First of all, toolbar style (theme) should be applied like so

<android.support.v7.widget.Toolbar
     app:theme="@style/AppTheme.Toolbar"
     android:layout_width="match_parent"
     android:layout_height="?attr/actionBarSize">
</android.support.v7.widget.Toolbar>

Next, values/styles.xml

<style name="AppTheme.Toolbar" parent="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
    <item name="actionButtonStyle">@style/AppTheme.Toolbar.ActionButton</item>
</style>
<!-- this will be applied regardless api version -->
<style name="Base.AppTheme.Toolbar.ActionButton" parent="@style/Widget.AppCompat.ActionButton">
    <item name="android:minWidth">0dp</item>
    <item name="android:minHeight">0dp</item>
</style>

<!-- this will be applied on < API 17 -->
<style name="AppTheme.Toolbar.ActionButton" parent="@style/Base.AppTheme.Toolbar.ActionButton">
    <item name="android:padding">0dp</item>
</style>

And the final move, values-v17/styles.xml

<!-- this will be applied on >= API 17 -->
<style name="AppTheme.Toolbar.ActionButton" parent="@style/Base.AppTheme.Toolbar.ActionButton">
    <item name="android:paddingStart">0dp</item>
    <item name="android:paddingEnd">0dp</item>
</style>
Mihail Ignatiev
  • 843
  • 6
  • 16
0

Well your question was about a year ago, but it may help to other peoples.

Check the solution here : how to add padding between menu items in android?

Setting the padding alone may not help. You must use minWidth attribute too. I'm using AppCompat too, absolutely works.

<style name="Theme.Styled" parent="@style/Theme.AppCompat.Light.DarkActionBar">
    <item name="actionButtonStyle">@style/Widget.Styled.Base.ActionButton</item>
</style>

<style name="Widget.Styled.Base.ActionButton" parent="@style/Widget.AppCompat.Base.ActionButton">
    <item name="android:minWidth">20dp</item>
    <item name="android:paddingLeft">0dp</item>
    <item name="android:paddingRight">15dp</item>
</style>
Community
  • 1
  • 1
Evren Ozturk
  • 918
  • 2
  • 19
  • 39
  • I'm trying to reduce the padding between menu items and I'm trying to use this same code and it doesn't have any effect! Any thoughts? – Burkely91 Aug 08 '15 at 08:47
  • I'm do not know how to reduce the specing between items. Codes above worked in 4 for different projects I worked. I have no idea why doesn't work for you :( I'm sure you've checked you are using the same theme. Btw. I got rid of any ready-to-use actionbar, toolbar etc. Try to write your own dynamic topbar library. Life is better this way. – Evren Ozturk Jun 02 '16 at 13:06