Redman Redman - 2 months ago 15
Android Question

ActionBar menu with text ,icon,text

Hello guys i want to display action like below enter image description here

my menu.xml file

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">

<item
android:id="@+id/action_show_ir_list"

android:showAsAction="ifRoom"
android:title="Cancel"/>


<item
android:id="@+id/phone"
android:title="Wowio"
android:icon="@drawable/logo"
android:showAsAction="ifRoom"
/>
<!--android:icon="@drawable/info"-->

<item
android:id="@+id/computer"
android:title="Done"

android:showAsAction="ifRoom"
/>


</menu>


in my main class

@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.menu, menu);

return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {

super.onOptionsItemSelected(item);

switch(item.getItemId()){
case R.id.phone:
Toast.makeText(getBaseContext(), "You selected About App", Toast.LENGTH_SHORT).show();
break;

case R.id.computer:


Toast.makeText(getBaseContext(), "You selected About Developer", Toast.LENGTH_SHORT).show();
break;
case R.id.action_show_ir_list:

Toast.makeText(getBaseContext(), "Volume Set To Max", Toast.LENGTH_SHORT).show();
break;

}
return true;

}


Here every thing is coming in over flow menu nothing is coming on action bar
enter image description here

I tried every thing on internet and nothing is working

What should i do to show them on ActionBar?

Answer
<menu xmlns:android="http://schemas.android.com/apk/res/android"
 xmlns:[yourapp]="http://schemas.android.com/apk/res-auto">
<item android:id="@+id/menu_add_size"
android:title="@string/menu_add_item"
android:orderInCategory="10"
[yourapp]:showAsAction="always"
android:icon="@android:drawable/ic_menu_add" />

instead of [yourapp] type your app name

Comments