overflow menu has no background - android

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.

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.

Selecting overflow menu item on TextView CustomActionModeCallback

I am trying to present a custom action bar while long pressing a textview. My menu has more than 5 items which causes some of the items to be present under the overflow menu.
When I press the overflow icon, the action bar gets destroyed and I am not able to choose any item inside the overflow.
ActionMode.Callback mActionModeCallback = new ActionMode.Callback() {
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
MenuInflater inflater = mode.getMenuInflater();
inflater.inflate(R.menu.add_rule_menu, menu);
return true;
}
public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
for (int i = 0; i < menu.size(); i++) {
MenuItem item = menu.getItem(i);
if (!mOptionsList.contains(item.getItemId()))
item.setVisible(false);
}
return false;
}
// Clicking on overflow button does not trigger this method at all.
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
switch (item.getItemId()) {
// Rest of the code
}
}
public void onDestroyActionMode(ActionMode mode) {}
};
textView.setCustomSelectionActionModeCallback(mActionModeCallback);
I filed an issue about this years ago, which has never been resolved.
A cheesy workaround is to use nested action modes. By this, I mean you have an item in an action mode that finishes the current mode and starts a new one, to provide a "drill-down menu" effect. I use this in my recently-resuscitated RichEditText widget, which offers an action mode for formatting text. I add a "format" item to the default action mode via setCustomSelectionActionModeCallback(). Tapping on "format" opens another action mode that offers options like bold and italic, along with further drill-downs to get to thinks like font changes.

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?

Android - checkable buttons on options menu

Can anyone point in the direction of any tutorials that show how to create an options menu with clicakble checks like in the picture below:
alt text http://img291.imageshack.us/img291/1221/deviceit.png
I have tried as follows:
/** Menu creation and setup **/
/* Creates the menu items */
public boolean onCreateOptionsMenu(Menu menu) {
boolean result = super.onCreateOptionsMenu(menu);
menu.add(0, 1, 0, "Speaker").setCheckable(true);
menu.add(0, 2, 0, "Mute").setCheckable(true);
return result;
}
/* Handles item selections */
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case 1:
if(audioManager.isSpeakerphoneOn()==false){
audioManager.setSpeakerphoneOn(true);
audioManager.setRouting(AudioManager.MODE_IN_CALL,
AudioManager.ROUTE_SPEAKER, AudioManager.ROUTE_ALL);
}else{
audioManager.setSpeakerphoneOn(false);
audioManager.setRouting(AudioManager.MODE_IN_CALL,
AudioManager.ROUTE_EARPIECE, AudioManager.ROUTE_ALL);
}
return true;
case 2:
if(audioManager.isMicrophoneMute())
audioManager.setMicrophoneMute(false);
else
audioManager.setMicrophoneMute(true);
return true;
}
return false;
}
But this doesn't work it only gives me text on the buttons on the options menu
EDIT: I have added the following onPrepareOptionsMenu method:
public boolean onPrepareOptionsMenu(Menu menu){
boolean result = super.onPrepareOptionsMenu(menu);
if(audioManager.isSpeakerphoneOn())
menu.findItem(1).setChecked(true);
else
menu.findItem(1).setChecked(false);
if(audioManager.isMicrophoneMute())
menu.findItem(2).setChecked(true);
else
menu.findItem(2).setChecked(false);
return result;
}
However I get the same outcome just text and no check light as in the picture above
If you want to change dynamically the state of your Option Menu, you need to use onPrepareMenu(). In this method, you can do dynamic checks and update anything you want.
Good luck!!
documentation
After some digging, this look like a custom view. I think your picture comes from this code.
This is an old question, but I had the same problem and searched a lot to find such an optionsMenu shown above. I found a tutorial on http://www.codeproject.com and modified it a little bit. Maybe it is not a profi-programmers-code, but it works for me. See my modifications at my (poor arranged) web page on google sites (I got an little tutorial too on this site):
https://sites.google.com/site/opiatefuchs/android-code-examples
This code is original from wjfrancis on the Code Project web page (many props):
http://www.codeproject.com/Articles/173121/Android-Menus-My-Way
I just modified it and would be glad if somebody got any ideas to improve this code. But for now, it works.

android: any tutorials on creating menus for apps?

I need a very simple menu which probably contains only one or two items: settings/options, where pressing one of them should show some customer defined parameters (is it called dialog), e.g., number of results shown. Is there any good tutorial on creating such kind of menus? I've looked at the "notepad" example in android, it doesn't really help.
Depending on what you're asking for, these are either "Options Menus" or "Context Menus", and creating them is very easy. Here's a link to the page on the Developers' Website explaining how to do menus.
Here's a basic example of code for options menus, adapted from my game:
public boolean onCreateOptionsMenu(Menu menu){
// Define your menu, giving each button a unique identifier numbers
// (MENU_PAUSE, etc)
// This is called only once, the first time the menu button is clicked
menu.add(0, MENU_PAUSE, 0, "Pause").setIcon(android.R.drawable.ic_media_pause);
menu.add(0, MENU_RESUME, 0, "Resume").setIcon(android.R.drawable.ic_media_play);
return true;
}
public boolean onPrepareOptionsMenu(Menu menu){
// This is called every time the menu button is pressed. In my game, I
// use this to show or hide the pause/resume buttons depending on the
// current state
}
public boolean onOptionsItemSelected(MenuItem item){
// and this is self explanatory
boolean handled = false;
switch (item.getItemId()){
case MENU_PAUSE:
pauseGame();
handled = true;
break;
case MENU_RESUME:
resumeGame();
handled = true;
break;
}
return handled;
}
Edit: See the comments for some details on AlertDialogs

Categories

Resources