prometheuspk prometheuspk - 4 months ago 18
Android Question

Menu Items are not showing on Action Bar

I have made a completely new project. I have added items to the

menu
layout file. Those items do not show up on the action bar's right side. I remember that an icon with three dots shows up which opens up the menu.

enter image description here

Here is my
Activity


public class MainActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ActionBar actionBar = getActionBar();
actionBar.setBackgroundDrawable(new ColorDrawable(Color.BLUE));
actionBar.show();
}

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

}


And here is my
main.xml


<menu xmlns:android="http://schemas.android.com/apk/res/android" >

<item
android:id="@+id/action_settings"
android:orderInCategory="100"
android:showAsAction="never"
android:title="@string/action_option1"/>
<item
android:id="@+id/action_settings34"
android:orderInCategory="100"
android:showAsAction="never"
android:title="@string/action_option2"/>
<item
android:id="@+id/action_settings3"
android:orderInCategory="100"
android:showAsAction="never"
android:title="@string/action_option3"/>


</menu>

Answer

Since you set the showAsAction attribute to never, then these menu items will never show as action views. Try this:

<menu xmlns:android="http://schemas.android.com/apk/res/android" >

    <item
        android:id="@+id/action_settings"
        android:orderInCategory="100"
        android:showAsAction="ifRoom|withText"
        android:title="@string/action_option1"/>
    <item
        android:id="@+id/action_settings34"
        android:orderInCategory="100"
        android:showAsAction="ifRoom|withText"
        android:title="@string/action_option2"/>
    <item
        android:id="@+id/action_settings3"
        android:orderInCategory="100"
        android:showAsAction="ifRoom|withText"
        android:title="@string/action_option3"/>

</menu>