Eman Ch
Eman Ch

Reputation: 192

Android action bar settings option not show on real device

i have action bar which have back button and settings option . when i run app on emmulator it show both back button and settings option. like as enter image description here

but on real device it not show settings option like as enter image description here

please tell me how to fix it?

this is my code of activity

 public class AddNewDish extends ActionBarActivity {
@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_add_new_dish);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);

@Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        MenuInflater inflater = getMenuInflater();
        inflater.inflate(R.menu.option, menu);
        return super.onCreateOptionsMenu(menu);

    }

this is menu xml code

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


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

Upvotes: 0

Views: 163

Answers (1)

Hiren Patel
Hiren Patel

Reputation: 52810

Put below code on onCreate() of ActionBarActivity:

try {
  ViewConfiguration config = ViewConfiguration.get(this);
  Field menuKeyField = ViewConfiguration.class.getDeclaredField("sHasPermanentMenuKey");

  if (menuKeyField != null) {
    menuKeyField.setAccessible(true);
    menuKeyField.setBoolean(config, false);
  }
}
catch (Exception e) {

}

Done

Upvotes: 1

Related Questions