android-optionsmenu

onSaveInstanceState() vs. onRetainCustomNonConfigurationInstance()

十年热恋 提交于 2019-12-05 21:52:27
I am using ActionBarSherlock, along with several MenuItem s that I dynamically manage, depending on program state. Specifically, I save the MenuItem s into instance variables in the Activity 's onCreateOptionsMenu() method, and then can show and/or hide them as needed later in the Activity . However, I found that the MenuItem variables can be lost on configuration changes, such as device rotation. So I also put them into a Parcel and pass them to onSaveInstanceState() for restoral through the savedInstanceState mechanism in the next onCreate() call, if needed. This seems to work fine in the

Options Menu does not appear in Action Bar on some devices

一世执手 提交于 2019-12-05 18:39:47
I have an options menu in the action bar, and it does not appear on certain devices which have hardware menu button. I must make it appear in the action bar despite having a hardware button... How can I do it? Put this in your onCreate method: 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) { } 来源: https://stackoverflow.com/questions/26010876/options-menu-does-not

No icon showing in Android Options menu item [duplicate]

牧云@^-^@ 提交于 2019-12-05 06:05:50
This question already has an answer here: Android options menu icon won't display 3 answers I have created an options menu with an icon I made myself (24px x 24px) but it is not showing. The code in my xml (located in res/menu) is the following: <?xml version="1.0" encoding="utf-8"?> <menu xmlns:android="http://schemas.android.com/apk/res/android" > <item android:id="@+id/menu_insert" android:icon="@drawable/menu_add" android:title="@string/menu_insert" /> </menu> The menu is created in my Activity.java file as said in the documentation: public boolean onCreateOptionsMenu(Menu menu) { super

Changing options menu icon in actionbar depending on an open Fragment

允我心安 提交于 2019-12-05 01:28:47
I have this item in my options menu: <item android:id="@+id/opt_mnu_action" android:icon="@android:drawable/ic_dialog_info" android:orderInCategory="1" android:showAsAction="ifRoom" android:title="New"> </item> The menu itself created in main FragmentActivity. I want to change this item's icon programmatically depending on the open Fragment and, obviously, have different actions when the user hits this button. I tried several things to do that, but nothing worked. The last thing I tried was this code in my Fragment's onCreateView method: MenuItem mi = (MenuItem) view.findViewById(R.id.opt_mnu

How can I use onCreateOptionsMenu in a Fragment within a tab Activity? (Sherlock ActionBar)

有些话、适合烂在心里 提交于 2019-12-04 08:49:49
问题 I have the following method overridden in my tab Activity and it works fine like that but I want specific option menu's for each fragment. When I put this in my fragment and press the menu button, nothing happens. @Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { MenuInflater inflater = getSupportMenuInflater(); inflater.inflate(R.menu.activity_calc, menu); return true; } 回答1: You need to call setHasOptionsMenu(true) on your fragment before it can participate in

Android: change width of overflow menu

十年热恋 提交于 2019-12-04 07:14:08
Currently I have an overflow menu which has default width: What I want is: I have tried changing the theme this way: <style name="MyWorkspaceDetailTheme" parent="@android:style/Theme.Holo.Light.DarkActionBar"> <item name="android:popupMenuStyle">@style/MyPopupMenu</item> </style> <style name="MyPopupMenu" parent="@android:style/Widget.Holo.ListPopupWindow"> <item name="android:dropDownWidth">30dp</item> </style> but didn't got any success. Please can anyone help. I was follwing this[ http://keepsafe.github.io/2014/11/19/building-a-custom-overflow-menu.html] tutorial but it did not mention way

How to add toggle button in menu item in android

梦想的初衷 提交于 2019-12-03 06:44:27
问题 I have options menu item in my application. Requirement was to add a toggle button to a menu item. Is this possible? 回答1: As of this writing there are 3 options . 1) Use app:actionViewClass . Example: <?xml version="1.0" encoding="utf-8"?> <menu xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto"> <item android:title="Switch!" app:actionViewClass="android.widget.Switch" app:showAsAction="always" /> </menu> 2) You can use a custom

How can I use onCreateOptionsMenu in a Fragment within a tab Activity? (Sherlock ActionBar)

南笙酒味 提交于 2019-12-03 02:06:52
I have the following method overridden in my tab Activity and it works fine like that but I want specific option menu's for each fragment. When I put this in my fragment and press the menu button, nothing happens. @Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { MenuInflater inflater = getSupportMenuInflater(); inflater.inflate(R.menu.activity_calc, menu); return true; } CommonsWare You need to call setHasOptionsMenu(true) on your fragment before it can participate in the action bar. May I suggest you check out http://code.google.com/p/sherlock-demo/ . As

How to add toggle button in menu item in android

本小妞迷上赌 提交于 2019-12-02 20:23:17
I have options menu item in my application. Requirement was to add a toggle button to a menu item. Is this possible? As of this writing there are 3 options . 1) Use app:actionViewClass . Example: <?xml version="1.0" encoding="utf-8"?> <menu xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto"> <item android:title="Switch!" app:actionViewClass="android.widget.Switch" app:showAsAction="always" /> </menu> 2) You can use a custom layout in a menu item to add toggle button. Example: Create a layout with Switch (alternatively, you may also

Option Menu does not appear in Android

南楼画角 提交于 2019-12-01 11:00:55
I have this code to create the menu: @Override public boolean onCreateOptionsMenu(Menu menu) { super.onCreateOptionsMenu(menu); MenuInflater inflater = getMenuInflater(); inflater.inflate(R.menu.tip_menu, menu); return true; } @Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case MNU_PREV: animateTextViewsPrev(); break; case MNU_NEXT: animateTextViewsNext(); break; } return true; } And the XML: <?xml version="1.0" encoding="utf-8"?> <menu xmlns:android="http://schemas.android.com/apk/res/android" > <item android:id="@+id/prev_tip" android:title="