Please help, I made a custom menu (added support libraries) (name-> main_activity_actions.xml)
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:yourapp="http://schemas.android.com/apk/res-auto" >
<item
android:id="@id/search"
android:icon="@drawable/search"
android:title="@string/search"
yourapp:showAsAction="ifRoom" />
<item
android:id="@id/view_all"
android:title="@string/view_all"
yourapp:showAsAction="never"/>
<item
android:id="@+id/action_settings"
yourapp:showAsAction="never"
android:title="@string/action_settings"/>
Now what should i do to put action_settings into three dots (of action bar), instead of hardware menu button (Without any hack).
MainActivity
@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_activity_actions, menu);
return true;
}
well i have found the hack but if there is any other way then let me know,
Hack
put this code in onCreate
try {
ViewConfiguration config = ViewConfiguration.get(this);
Field menuKeyField = ViewConfiguration.class.getDeclaredField("sHasPermanentMenuKey");
if(menuKeyField != null) {
menuKeyField.setAccessible(true);
menuKeyField.setBoolean(config, false);
}
} catch (Exception ex) {
// Ignore
}
for this you need to import
import java.lang.reflect.Field;
import android.view.ViewConfiguration;