Reputation: 1271
So I did exactly what i suppose to do according to the android development training but still i cant see the actions on the action bar, instead they are in the overflow menu.
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<!-- Search, should appear as action button -->
<item
android:id="@+id/action_search"
android:icon="@drawable/ic_action_search"
android:showAsAction="ifRoom"
android:title="@string/action_search"/>
<!-- Settings, should always be in the overflow -->
<item
android:id="@+id/action_settings"
android:showAsAction="never"
android:title="@string/action_settings"/>
</menu>
public class MainActivity extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
and also i set that:
<uses-sdk
android:minSdkVersion="11"
android:targetSdkVersion="21" />
what can i do now?
Upvotes: 0
Views: 239
Reputation: 1432
You can always force the menu entries to appear by changing myapp:showAsAction="ifRoom"
to myapp:showAsAction="always"
Don't forget to define your app namespace before: xmlns:myapp="http://schemas.android.com/apk/res-auto"
Quoting from docs for the namespace change:
The showAsAction attribute above uses a custom namespace defined in the tag. This is necessary when using any XML attributes defined by the support library, because these attributes do not exist in the Android framework on older devices. So you must use your own namespace as a prefix for all attributes defined by the support library.
Maybe the name of your app is too big and that's why the menu entries don't appear.
Upvotes: 0
Reputation: 6847
It's kind of a bug. You should apply another namespace:
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<!-- Search, should appear as action button -->
<item
android:id="@+id/action_search"
android:icon="@drawable/ic_action_search"
app:showAsAction="ifRoom"
android:title="@string/action_search"/>
<!-- Settings, should always be in the overflow -->
<item
android:id="@+id/action_settings"
android:showAsAction="never"
android:title="@string/action_settings"/>
</menu>
Upvotes: 1