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?
Related
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.
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.
I am using SearchView from Support Library in my Appcombat Actionbar.
On emulator it all works as intended. I can open it by clicking the menu item or using the Search Button on the device and the keyboard is shown.
#Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if(keyCode == KeyEvent.KEYCODE_SEARCH) {
if(!MenuItemCompat.isActionViewExpanded(searchItem)) {
MenuItemCompat.expandActionView(searchItem);
} else MenuItemCompat.collapseActionView(searchItem);
}
return super.onKeyDown(keyCode, event);
}
On Expanding I set a saved text.
MenuItemCompat.setOnActionExpandListener(searchItem, new MenuItemCompat.OnActionExpandListener(){
#Override
public boolean onMenuItemActionCollapse(MenuItem item) {
// TODO Auto-generated method stub
return true;
}
#Override
public boolean onMenuItemActionExpand(MenuItem item) {
searchView.onActionViewExpanded(); // to initialize searchview
searchView.setQuery(searchText, false);
searchView.requestFocus();
return true;
}
});
Problem:
On my hardware device (HTC Desire HD, Android 2.3), when I press the device's Search Button the searchview expands and the softkeyboard shows for a part of a second and hides again. Clicking the MenuItem works fine and shows the keyboard as intended. There seems to be a method hiding the keyboard again after focusing the searchview. I already tried several stuff (setOnQueryTextFocusChangeListener with manually showing softInput) but none seem to work on my device.
I hope someone got a solution. Thanks
It looks like your searchView has lost focus after setting the searchText.
try adding this before calling requestFocus.
searchView.setFocusable(true);
#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.
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;
}
}