My app uses the old-style options menu. Currently we target API 9. On the Galaxy S4 I notice the following behavior:
At this point, tapping on any element in the options menu (including the "More") option seems to have no effect. However the system is actually caching those taps. If the user taps the a menu five times (with no visible effect) then taps the back button to hide the menu, then taps the menu button to display the menu once again, all the cached taps take place right away. onOptionsMenuItemSelected() is called once for every time the user tapped that menu item.
This only happens on the S4 (and possibly other Samsung devices). Notably, I don't see this behavior using a Galaxy Nexus running stock 4.2.2.
Is this a bug with Samsung's customization of Android, or is it more likely I'm doing something wrong in my app and the stock Android code is just more forgiving?
The below code for customized menu and tested with galaxy S3 running jelly bean 4.2.1 and work perfectly ,
unfortunately i don't have S4 , but you can check it also this is without more button:
public class CustomMenu extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
public boolean onCreateOptionsMenu(android.view.Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.cool_menu, menu);
getLayoutInflater().setFactory(new Factory() {
public View onCreateView(String name, Context context,
AttributeSet attrs) {
if (name.equalsIgnoreCase(
"com.android.internal.view.menu.IconMenuItemView")) {
try {
LayoutInflater li = LayoutInflater.from(context);
final View view = li.createView(name, null, attrs);
new Handler().post(new Runnable() {
public void run() {
// set the background drawable if you want that
//or keep it default -- either an image, border
//gradient, drawable, etc.
view.setBackgroundResource(R.drawable.myimage);
((TextView) view).setTextSize(20);
// set the text color
Typeface face = Typeface.createFromAsset(
getAssets(),"OldeEnglish.ttf");
((TextView) view).setTypeface(face);
((TextView) view).setTextColor(Color.RED);
}
});
return view;
} catch (InflateException e) {
//Handle any inflation exception here
} catch (ClassNotFoundException e) {
//Handle any ClassNotFoundException here
}
}
return null;
}
});
return super.onCreateOptionsMenu(menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.AboutUs:
Intent i = new Intent("com.test.demo.ABOUT");
startActivity(i);
break;
case R.id.preferences:
Intent p = new Intent("com.test.demo.PREFS");
startActivity(p);
break;
case R.id.exit:
finish();
break;
}
return false;
}
}
Dont forget to create folder called menu in res folder, and inside the menu folder create an XML for your menu (e.g. cool_menu.xml) such as this:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:title="about"android:id="@+id/AboutUs" />
<item android:title="Prefs" android:id="@+id/preferences" />
<item android:title="Exit" android:id="@+id/exit" />
</menu>
Hope that will help.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With