Android Question Distance between menu icons on ACToolBar

RB Smissaert

Well-Known Member
Licensed User
Longtime User
Adding action icons (just letters) to a ACToolBarLight, used as an actionbar.

This is the code I use for that:

B4X:
Sub TextToBitmapDrawable (s As String, FontSize As Float, lFontColour As Long) As BitmapDrawable

Dim bmp As Bitmap
Dim cvs As Canvas
Dim bmpD As BitmapDrawable

bmp.InitializeMutable(16dip, 16dip)
cvs.Initialize2(bmp)
Dim h As Double = cvs.MeasureStringHeight(s, lblID.Typeface, FontSize)
cvs.DrawText(s, bmp.Width / 2, bmp.Height / 2 + h / 2, lblID.Typeface, FontSize, lFontColour, "CENTER")
bmpD.Initialize(bmp)

Return bmpD

End Sub


Sub Activity_CreateMenu(Menu As ACMenu)

Dim item As ACMenuItem

Menu.Clear
item = Menu.Add2(1, 1, "Find", TextToBitmapDrawable("F", 16, Colors.RGB(0, 0, 0)))
item.ShowAsAction = item.SHOW_AS_ACTION_ALWAYS
item = Menu.Add2(2, 2, "Pat", TextToBitmapDrawable("P", 16, Colors.RGB(0, 0, 255)))
item.ShowAsAction = item.SHOW_AS_ACTION_ALWAYS
item = Menu.Add2(3, 3, "Meds", TextToBitmapDrawable("M", 16, Colors.RGB(255, 0, 0)))
item.ShowAsAction = item.SHOW_AS_ACTION_ALWAYS
item = Menu.Add(4, 4, "Settings", Null)

End Sub

This works fine, but the icons are too far apart and I am running out of space.
Is there any way to get these icons closer together?


RBS
 

RB Smissaert

Well-Known Member
Licensed User
Longtime User

Thanks, got there in the end:

B4X:
CreateResource(values, themes.xml,
<resources>
<dimen name="action_button_padding">0dp</dimen>
<style name="MyAppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimary">#FF9800</item>
<item name="colorPrimaryDark">#F57C00</item>
<item name="colorAccent">#FFA726</item>
<item name="windowNoTitle">true</item>
<item name="windowActionBar">false</item>
<item name="windowActionModeOverlay">true</item>
<item name="android:actionButtonStyle">@style/ActionButton</item>
</style>
<style name="ActionButton" parent="@android:style/Widget.ActionButton">

<item name="android:paddingStart">0dp</item>
<item name="android:paddingEnd">0dp</item>
<item name="android:minWidth">0dp</item>

<item name="android:drawablePadding">@dimen/action_button_padding</item>
</style>
</resources>
)

RBS
 
Upvote 0
Top