Reputation: 963
I have tried adding it by looking at various guides and stackOverflow topics, but they didn't help. I do everything as various guides say, but I am still unable to get settings icon at the action bar. MainActivity.class:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ActionBar actionBar = getSupportActionBar();
actionBar.setDisplayHomeAsUpEnabled(true);
if (savedInstanceState == null) {
getSupportFragmentManager().beginTransaction()
.add(R.id.container, new PlaceholderFragment())
.commit();
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.entry_test, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item){
Intent myIntent = new Intent(getApplicationContext(),MainActivity.class);
startActivityForResult(myIntent, 0);
return true;
}
entry_test.xml (this is where the icon is):
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="@+id/action_cart"
android:icon="@drawable/ic_action_settings"
android:orderInCategory="100"
android:showAsAction="always"
android:title="Settings"
/>
</menu>
The icon is not displayed in the action bar and when pressing "more" button (or whatever it is called), a button appears at the bottom saying Settings (title of it). Thats it. What am I doing wrong?
Upvotes: 1
Views: 1524
Reputation: 3731
Since you are using an ActionBar via the support library, try the following:
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:yourapp="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/action_cart"
android:icon="@drawable/ic_action_settings"
android:orderInCategory="100"
android:showAsAction="always"
yourapp:showAsAction="always"
android:title="Settings" />
</menu>
Upvotes: 7