0

I created an item "+" that i want to appear next to the three dots menu on the top left.

so this is the xml:

<menu xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    tools:context="com.example.ali.test1.MainActivity">
    <item android:id="@+id/action_settings" android:title="@string/action_settings"
        android:orderInCategory="1" app:showAsAction="never" />

    <item
        android:id="@+id/action_cart"
        android:title="+"
        android:orderInCategory="2"
        android:showAsAction="always"/>
</menu>

now I'm getting the "+" item inside the action_settings and not on the side

I did check "Show Menu item always in support action bar" but it did not help

any help ?

2 Answers2

0

try changing always to ifRoom and take out android:orderInCategory="2"

<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:context="com.example.ali.test1.MainActivity">

<item
    android:id="@+id/action_cart"
    android:title="+"
    app:showAsAction="ifRoom"/>
<item 
    android:id="@+id/action_settings"
    android:title="@string/action_settings"
    android:orderInCategory="1" app:showAsAction="never" />

check you are using that menu in the activity

 @Override 
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present. 
    getMenuInflater().inflate(R.menu.**themenuyouareusing**, menu);


    return true; 
} 
Juan Diaz
  • 224
  • 2
  • 9
0

first remove android:orderInCategory and then put action_cart before action_settings

and try to use only android:showAsAction instead of app:showAsAction

so your xml should look like this:

<menu xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    tools:context="com.example.ali.test1.MainActivity">

    <item
        android:id="@+id/action_cart"
        android:title="+"
        android:showAsAction="always"/>

    <item 
        android:id="@+id/action_settings" 
        android:title="@string/action_settings"
        android:showAsAction="never" />
</menu>
Naheel
  • 497
  • 3
  • 13