how to add padding between menu items in android?
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>
How to increase padding or margin between menu item icon and title in app toolbar?
I can't believe it took me so long to figure this out!
Eventually it occurred to me to use the Android Device Monitor. I went to Tools > Android > Android Device Monitor. When that started up, I clicked the package name of my app in the "Devices" tab and then I clicked the "Dump View Hierarchy for UI Automator" button (which looks like multiple phones stacked on top of each other) at the top of the "Devices" tab. This showed me the UI of my current screen. Then I could click on the "Refresh" button and discover that it was not two Views next to each other--it was one TextView with a DrawableLeft. I know, I know, that's obvious and should have been the first thing I thought of.
I had already found ActionBarSherlock - How to set the padding of each actionbar's icon? , but that didn't work for me. However, that gave me an example of something I needed--changing the ActionButton style.
Now that I knew it was a TextView with a DrawableLeft, I knew I needed to change DrawablePadding. That's the change I needed to make to styles.
To change the ActionButton theme I needed to add this to my styles.xml:
<style name="ActionButton" parent="@android:style/Widget.ActionButton">
<item name="android:drawablePadding">@dimen/action_button_padding</item>
</style>
dimen.xml:
<dimen name="action_button_padding">4dp</dimen>
Then a tweak to the Theme section of style.xml:
<style name="Theme.MyTheme"
parent="Theme.AppCompat.Light.NoActionBar">
<!-- other styles -->
<item name="android:actionButtonStyle">@style/ActionButton</item>
</style>
And it just works! No need to set a custom ActionProvider, edit the image to add spacing in the image file, or use extra XML files for each button.
Adding margin to MenuItem in Android
Using java:
View view = new View(this);
menuItem.setActionView(view);
view.setPadding(16,0,0,0); //left , top ,right , bottom
Or XML :
Add this style to your toolbar , for your icon.
<style name="myToolbarStyle" parent="@style/Widget.AppCompat.Toolbar">
<item name="android:paddingLeft">16dp</item>
</style>
Of course if you have more items , you'll need to create a particular style for that item that you want left padding.
how to change margin between items in popupmenu
You need to set your preferred item row height in your AppTheme inside styles.xml
:
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="android:listPreferredItemHeightSmall">20dp</item>
</style>
You may need to modify this number a bit to get the correct value, but it determines the height of those rows. Make sure to replace Theme.AppCompat.Light.DarkActionBar
with whatever you're currently using.
As for setting a maximum height, I'm afraid you'll have to create your own extension class for that, as in this example.
Related Topics
Android: Save File Permanently (Even After Clear Data/Uninstall)
Difference Between Android Dimension: Pt and Dp
How to Get Screen Display Metrics in Application Class
Android Approach for "Rate My Application"
Android: Velocity-Based Viewpager Scrolling
How to Create a Looper Thread, Then Send It a Message Immediately
Right Align Text in Android Textview
How to Discover Zeroconf (Bonjour) Services on Android? I'M Having Trouble with Jmdns
Splash Screen While Loading a Url in a Webview in Android App
Firebase Servervalue.Timestamp in Java Data Models Objects
Android: HTML in Textview with Link Clickable
Why Is 0Dp Considered a Performance Enhancement
What Is The Easiest Way to Use Svg Images in Android
How to Keep The Oauth Consumer Secret Safe, and How to React When It's Compromised