I want to edit my menu bar in such a way that it has only two buttons and they are placed at the beginning and the end of the action bar. By default they appear to be automatically placed at the end of the action bar. Searching their attributes I was not able to find any that position the item elements. How can I get from where I am to what I need?
My XML:
<?xml version="1.0" encoding="utf-8"?>
<item
android:id="@+id/Menu"
android:orderInCategory="0"
android:title="@string/Menu"
app:showAsAction="always" />
<item
android:id="@+id/Bucket"
android:title="@string/Bucket"
app:showAsAction="always"
android:orderInCategory="1"/>
What I currently have:
What I want to achieve:
EDIT: created a custom action bar and am attempting to inflate it, however I receive a null pointer exception and run time exception at the fourth and fifth line of the newly added code:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.pogolemotoproektce, PID: 8377
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.pogolemotoproektce/com.example.pogolemotoproektce.HomeActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.app.ActionBar.setDisplayOptions(int)' on a null object reference
This is the added code:
final ActionBar actionBar = getActionBar();
LayoutInflater inflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view = inflater.inflate(R.layout.custom_action_bar, null);
actionBar.setCustomView(view, new ActionBar.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);