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;
}
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>
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With