Options menu in Samsung Galaxy S3
Is it possible to force the Samsung Galaxy S3 to have a fixed position of the options menu in the upper right corner of the screen, as it happens in other popular phones? In the Samsung Galaxy S3 function menu, only accessible under the menu button. I would like to place inline help in an application at a fixed location on all types of devices.
I'm not sure if a similar problem occurs on other types of phones / tablets.
source to share
Use this block of code in your activity that contains a menu option.
try {
ViewConfiguration config = ViewConfiguration.get(BaseActivity.this);
Field menuKeyField = ViewConfiguration.class
.getDeclaredField("sHasPermanentMenuKey");
if (menuKeyField != null) {
menuKeyField.setAccessible(true);
menuKeyField.setBoolean(config, false);
}
} catch (Exception e) {
e.printStackTrace();
}
with this block, you can access the options menu from the top right corner of the action bar. Even on the Samsung Galaxy S3, when you press the menu button, the options menu opens in the upper right corner. try using the following menu.xml
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:orderInCategory="2"
android:title="Home"/>
<item
android:id="@+id/logs"
android:orderInCategory="3"
android:title="Logs"/>
<item
android:id="@+id/support"
android:orderInCategory="4"
android:title="Support"/>
<item
android:id="@+id/logout"
android:orderInCategory="5"
android:title="Logout"/>
</menu>
source to share
you can try this. in your activity:
@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;
}
@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();
switch (id) {
case R.id.action_whatever:
// do your thing here
return true;
}
return super.onOptionsItemSelected(item);
}
in / res / menu / main.xml
<item android:id="@+id/action_whatever"
android:title="@string/action_text"
android:orderInCategory="100"
android:icon="@drawable/ic_overflow"
android:showAsAction="always" />
source to share