Android Question Menu Bar - Space between menu icons?

GuyBooth

Active Member
Licensed User
Longtime User
I have two menu items that have icons on the Action bar that are too close together to allow for user mistakes.
To get around this, I have added a third "Blank" menu with a blank icon which sits between the other two. The code is:
B4X:
        ' Activity Bar Menu Item for connections:
        Activity.AddMenuItem3("Connections","Set_Connections",LoadBitmapResize(File.DirAssets, "icon-communication 32x32.png",28dip,28dip, True),True)
        ' Blank menu to provide some space between Connections and other menu icons
        Activity.AddMenuItem3("","Blank", LoadBitmapResize(File.DirAssets, "tmm_blank.png",28dip,28dip, True),True)
        ' Activity Bar Menu Item to raise the Play Bar menu:
        Activity.AddMenuItem3("Play Bar","PlayBar",LoadBitmapResize(File.DirAssets, "tmm_logoplay.png",28dip,28dip, True),True)
Is there a better way to create space between menu the icons? What I have works, but I would like the space between the two active menu items to be about half of what I have created here.
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
If you are using AppCompat then you can change the padding with the following manifest editor code:
B4X:
CreateResource(values, dimen.xml,
<resources>
<dimen name="action_button_padding">40dp</dimen>
</resources>
)
Add to the theme.xml resource:
B4X:
 <item name="android:actionButtonStyle">@style/ActionButton</item>
And:
B4X:
<style name="ActionButton" parent="@android:style/Widget.ActionButton">
       <item name="android:drawablePadding">@dimen/action_button_padding</item>
   </style>

Full theme code for example:
B4X:
CreateResource(values, theme.xml,
<resources>
    <style name="MyAppTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <item name="colorPrimary">#FFFE0000</item>
        <item name="colorPrimaryDark">#FFFA00D9</item>
        <item name="android:textColorSecondary">#FFFF0000</item>
        <item name="colorAccent">#FF0025FC</item>
        <item name="windowNoTitle">true</item>
        <item name="windowActionBar">false</item>
       <item name="android:navigationBarColor">#FFFE0000</item>
       <item name="android:textColorPrimary">#FFFF0000</item>
        <item name="android:actionButtonStyle">@style/ActionButton</item>
    </style>
   <style name="ActionButton" parent="@android:style/Widget.ActionButton">
       <item name="android:drawablePadding">@dimen/action_button_padding</item>
   </style>
</resources>
)

Based on: https://stackoverflow.com/questions...nu-item-icon-and-title-in-app-toolba/39900234
 
Upvote 0

GuyBooth

Active Member
Licensed User
Longtime User
Thanks.
I'm not using AppCompat, trying to keep my life simple :)

Can I change the padding in a custom theme I'm already using?
 
Upvote 0

GuyBooth

Active Member
Licensed User
Longtime User
Try to apply the changes above to your theme.
Well it looks like it ought to work but I applied this code:
B4X:
CreateResource(values, dimen.xml,
   <resources>
   <dimen name="action_button_padding">40dp</dimen>
   </resources>
)
CreateResource(values,theme.xml,
<resources>
   <style name="TMM_Theme_2" parent="@android:style/Theme.Material">
    <item name="android:textAllCaps">false</item>
        <item name="android:actionButtonStyle">@style/ActionButton</item>
   </style>
   <style name="ActionButton" parent="@android:style/Widget.ActionButton">
       <item name="android:drawablePadding">@dimen/action_button_padding</item>
   </style>
</resources>
)

and compiling yielded this error:
B4X:
Generating R file.    Error
res\values-v21\theme.xml:2: error: Error parsing XML: not well-formed (invalid token)

Tried a few variations of this without success, but I am perhaps not familiar enough with xml?
 
Upvote 0
Top