I have this layout that add 1 or more items into the ActionBar
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="@+id/item_test"
android:showAsAction="always|withText"
android:title="SearchIcon"/>
</menu>
And then I will add another item dynamically into the ActionBar from another Fragment or Activity
MenuItem populateItem = menu.add("My New Item - Reload Icon");
But I want the item that I just added to stay in front of the items I had before, like the picture:
If I add it like I did, the icons will be shown as the last picture, how can I get the alignment like in the second picture?
You will have to create a custom view for that. You can't use the options menu inflation for your use case. Set the style of the activity to Theme. AppCompat and don't use NoActionBar in the activity or the application style.
android:windowActionBar denotes property for lollipop and above only. Where as windowActionBar denotes for all versions and is retrieved from support library. Follow this answer to receive notifications.
Android ActionBar is a menu bar that runs across the top of the activity screen in android. Android ActionBar can contain menu items which become visible when the user clicks the “menu” button.
You can re-order the menu items with the android:orderInCategory attribute in each you need to move. You have to play around with that option alogn with menuCategory.
For example, assign to all items:
android:menuCategory="system"
Then, just set lower orderInCategory values to the Items you want to keep on the left.
Order in category determines the order appearance, from low to high.
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