Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to add padding between menu items in android? [duplicate]

enter image description here

I'm having menu items being inflated from res/menu/menu.xml on to ActionBar, how do I add padding between menu items using android?

<item 
    android:id="@+id/home"
    android:showAsAction="always"
    android:title="Home"
    android:icon="@drawable/homeb"/>
<item 
    android:id="@+id/location"
    android:showAsAction="always"
    android:title="Locations"
    android:icon="@drawable/locationb"/>
<item
    android:id="@+id/preQualify"
    android:showAsAction="always"
    android:title="Pre-Qualify"
    android:icon="@drawable/prequalityb"/>
<item 
    android:id="@+id/products"
    android:showAsAction="always"
    android:title="Products"
    android:icon="@drawable/productb"/>

Java file:

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.activity_store_locator, menu);
    return true;
}
like image 619
Anil M Avatar asked Mar 28 '13 09:03

Anil M


2 Answers

Found solution, added following lines in styles.xml file and it worked!!

<style name="AppTheme" parent="AppBaseTheme">
    <item name="android:actionButtonStyle">@style/MyActionButtonStyle</item>
</style>

<style name="MyActionButtonStyle" parent="AppBaseTheme">
    <item name="android:minWidth">20dip</item>
    <item name="android:padding">0dip</item>
</style>
like image 143
Anil M Avatar answered Oct 31 '22 15:10

Anil M


create drawable xml . like res/drawable/shape_green_rect.xml

<?xml version="1.0" encoding="utf-8"?>
<shape
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:shape="rectangle">

  <!-- Specify a semi-transparent solid green background color -->
  <solid android:color="#5500FF66" />

  <!-- Specify a dark green border -->
  <stroke 
    android:width="5dp"
    android:color="#009933" />

  <!-- Specify the margins that all content inside the drawable must adhere to -->
  <padding
    android:left="30dp"
    android:right="30dp"
    android:top="30dp"
    android:bottom="30dp" />
</shape>

Add this drawable in

android:icon="@drawable/shape_green_rect"

This way we can able to add padding in menu.

Thanks.

like image 37
Md Abdul Gafur Avatar answered Oct 31 '22 15:10

Md Abdul Gafur