MenuInflater feature doesn't work on other devices? - android

#Override
public boolean onCreateOptionsMenu(Menu menu) {
// TODO Auto-generated method stub
MenuInflater blowUp = getMenuInflater();
blowUp.inflate(R.menu.help_menu, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// TODO Auto-generated method stub
switch (item.getItemId()) {
case R.id.help:
Intent z = new Intent(EpicShit.this, Help.class);
startActivity(z);
break;
case R.id.exit:
finish();
break;
}
return true;
}
This is the code that i'm running for the menuinflater. I'm currently using a HTC One S and this works, as i get what it should, which are "Help" & "Exit". But when i tried this on a Samsung S2, there isn't even a place for me to choose these 2 options from. It's just not there. Could this be because we have different versions (my program doesn't support older versions)? Or am i programmatically incorrect? Also, i don't have the code for this right now, but it's a similar problem: soundpool and setAlpha don't work on the S2, but works on HTC One S.

Depends on what you put in your menu/main.xml
android:showAsAction="ifRoom"
will appear in the action bar for Android 4.0+, while
android:showAsAction="Never"
will only show up when the Menu key is pressed.
The Galaxy S2 doesn't show the action bar (because it's a Gingerbread phone), while One S does.

Related

Overflow menu layout lag

When I'm opening the overflow menu, at first I see just an empty layout, and only after that the menu with text appears:
The same thing happens when the overflow menu is closing:
Creating this menu seems to be standard:
#Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.action_bar_menu, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.action_cp:
return true;
case R.id.action_settings:
return true;
case R.id.action_used_libraries:
return true;
case R.id.action_help_and_feedback:
return true;
default:
return super.onOptionsItemSelected(item);
}
}
why does it happen and how to get rid of this lag?
Try removing <item name="android:background">#color/yourgreencolor</item> from both your ThemeOverlay.AppTheme.ActionBar and ThemeOverlay.AppTheme.PopupMenu style, it's rendering a background first. I used parent="ThemeOverlay.AppCompat.Light" to have my desired white background, maybe that could help you find out how to have a green background despite this issue. It's definitively possible to have custom colors without this, I've seen some.

overflow menu has no background

For some reason, the background tiles for the options are not showing when I click the overflow button at the bottom of the screen.
I have gone over the code, but I can't find anything that would cause such a thing. There is basically no background behind the text. If I change the background colour to black then the text won't be seen.
Here is all the code related to the menu options:
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.new_game:
gameView.startNewGame();
return true;
case R.id.stats:
return true;
case R.id.help:
gameInfo.show();
return true;
default:
return super.onOptionsItemSelected(item);
}
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.menu_main, menu);
return (super.onCreateOptionsMenu(menu));
}
Also according to this post: https://stackoverflow.com/a/13689548/1973276, the way to get the overflow button to show at the bottom is to set the tarketSDKVersion to 13. That is what I did to get it to appear at the bottom of the screen, but since that reply was 2 years ago, SDK 13 has long be replaced and it is recommended to use the latest SDK. Is there a better way in placing the overflow button in the bottom bar?
Any help would be appreciated.

Android actionbar menu icon now shown in tablet

I've developed an application which contains a menu icon in my actionbar, I create the menu as below:
#Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.main, menu);
return true;
}
and here's the code for the onOptionsItemSelected:
#Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.menu_home:
startActivity(new Intent(this, MainActivity.class));
return true;
case R.id.menu_adv_search:
startActivity(new Intent(this, AdvSearchActivity.class));
return true;
default:
return super.onOptionsItemSelected(item);
}
}
using my smart phone the menu icon is there (using LG phone), but when I test it on my tablet (Galaxy Tab 8) the menu icon is gone, but the functionality is still there. pressing the menu soft button at the bottom, the popup appears, but the icon is missing from the top action bar. How to fix it? any ideas?
On devices with hardware menu buttons ( for example Galaxy series of samsung) the overflow menu behaves as the 'traditional' menu, by using the hardware menu button.
please use following attribute for each of your menu item
android:showAsAction="always"
if you are using actionbarcompat pack , then instead of above attribute use following
app:showAsAction="always"
don't forget to add the following namespace aswell
xmlns:app="http://schemas.android.com/apk/res-auto"
As I found out, on devices with menu button hardware provided, the menu icon will be hidden and making the menu item showAsAction="always" will not bring the menu icon back it in my question I was intending to, so I've found the solution Here
and here's the code I've used from the above link to overcome this issue(if it can be called an issue):
private void getOverflowMenu() {
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) {
e.printStackTrace();
}
}
you can just put this function in your activity or base activity and call it in your onCreate function and it will do all the magic for ya.

Hardware menu button not opening in Samsung galaxy tab 3

I have a samsung galaxy tab3 and I have the menu implemented in the usual manner - i.e.
#Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.game_menu, menu);
return true;
}
and for menu selected
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle item selection
switch (item.getItemId()) {
case R.id.new_game:
newGame();
return true;
case R.id.help:
showHelp();
return true;
default:
return super.onOptionsItemSelected(item);
}
}
In my xml ive used android:showAsAction="never" for items that I want to see in overflow and android:showAsAction="ifRoom" for items I want to see upfront. But in this tablet I see only the ones with ifRoom set and the others just disappear and the menu button does not show the overflow items. I've looked at all answers on SO and tried the popular ones like setting minimum and target sdk versions to less than 11 and so on. But the menu just wont come up. It works fine in devices that dont have the capacitive menu touch and an overflow button is shown in the action bar.
Well it ended up working when I programmatically called openOptionsMenu with onKeyDown
#Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_MENU) {
openOptionsMenu();
}
return true;
};
MAybe you have a theme (like full screen) that does not support an ActionBar?

If showPopup only goes to API 11, how do I link a Menu to a View with ABS?

Note: PopupMenu is available with API level 11 and higher.
http://developer.android.com/guide/topics/ui/menus.html#PopupMenu
With that in mind, how can I link a menu to a View on screen with ABS and the compatibility library? I have a menu imageview on one of my layouts that I would like to provide a universal menu option. Basically by having an imageview that pops up the menu, the same system is in use regardless of device or android version. But if popup only exists on Gingerbread and later, is there another way to link an ImageView (+ click listener) to open up my menu?
Here's how I ended up solving this:
ImageView menuImg = (ImageView) activity.findViewById(R.id.menuImageView);
menuImg.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
activity.openOptionsMenu(); //This is the key method!
}
});
public boolean onCreateOptionsMenu(Menu menu) {
com.actionbarsherlock.view.MenuInflater inflater = getSupportMenuInflater();
inflater.inflate(R.menu.main_menu, menu);
return true;
}
public boolean onMenuItemClick(MenuItem item) {
switch (item.getItemId()) {
case R.id.demographics:
return true;
case R.id.settings:
Log.v("v", "settings clicked");
return true;
default:
return false;
}
}

Categories

Resources