android-menu

What is the difference between onCreateOptionsMenu(Menu menu) and onPrepareOptionsMenu(Menu menu)?

拟墨画扇 提交于 2019-12-02 18:43:59
Explain difference between onCreateOptionsMenu(Menu menu) and onPrepareOptionsMenu(Menu menu) . onCreateOptionsMenu() is called once. onPrepareOptionsMenu() is called every time the menu opens. From the onCreateOptionsMenu() documentation: This is only called once, the first time the options menu is displayed. To update the menu every time it is displayed, see onPrepareOptionsMenu(Menu) . 来源: https://stackoverflow.com/questions/14043631/what-is-the-difference-between-oncreateoptionsmenumenu-menu-and-onprepareoptio

Use different icons with different Android SDK versions

时光毁灭记忆、已成空白 提交于 2019-12-02 17:18:45
I have icons for my Android menu. On Android 3+ I'm using a black ActionBar so the icons are white. However, on Android 2.x the menu is inherently white which means the icons are nearly invisible. How can I use different menu icons for different versions? I'm assuming I can do it using different drawable directories like res/drawable-mdpi-v11, but I'm wondering if there is another way so I don't have to create a bunch of different directories as I add versions or pixel densities. EDIT: I put dark versions in res/drawable-mdpi and res/drawable-hdpi for use with Android 2.x and I put light

Why is menu of AppCompatActivity.onMenuOpened(int featureId, Menu menu) null?

不羁的心 提交于 2019-12-01 22:03:14
问题 An Android app has the following code: public class FooActivity extends AppCompatActivity{ @Override public boolean onMenuOpened(int featureId, Menu menu) { } } When the 3-dot overflow menu button is clicked, the menu is displayed normally, and this MenuOpened(int featureId, Menu menu) is called, but menu is null. Is this normal? 回答1: When you click the menu icon onMenuOpened is called twice: first time immediately, then when menu is prepared. Obviously first time it is null because it is not

actionbar setnavigationmode deprecated

穿精又带淫゛_ 提交于 2019-12-01 19:09:53
Hi I'm making an app in which I plan on showing floor & category wise listing of stores inside a mall. Below snap show an activity showing floor wise listing of stores I was thinking of adding a spinner in the ActionBar showing "by Floor" and "by Category" as options. Clicking on "by Category" would arrange the stores according to the category in which they belong. After googling a bit I found getActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_LIST); would be apt but now I see that its deprecated, putting it as an action item in the activity menu doesn't look like a very good idea. Any

Why the pictures/icon don't show up in the menu?

廉价感情. 提交于 2019-12-01 11:22:13
I followed this tutorial to create a menu but my menu looks differently: How can I create a menu with images? This is my code: <menu xmlns:android="http://schemas.android.com/apk/res/android"> <item android:id="@+id/preferences" android:icon="@drawable/preferences" android:title="Preferences" /> <item android:id="@+id/help" android:title="Help" android:icon="@drawable/ic_action_search" /> </menu> @Override public boolean onCreateOptionsMenu(Menu menu) { /*menu.add(Menu.NONE, PREF_ID, Menu.NONE, "Preferences") .setIcon(R.drawable.preferences).setAlphabeticShortcut('e'); return (super

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="

Why the pictures/icon don't show up in the menu?

北城以北 提交于 2019-12-01 09:05:58
问题 I followed this tutorial to create a menu but my menu looks differently: How can I create a menu with images? This is my code: <menu xmlns:android="http://schemas.android.com/apk/res/android"> <item android:id="@+id/preferences" android:icon="@drawable/preferences" android:title="Preferences" /> <item android:id="@+id/help" android:title="Help" android:icon="@drawable/ic_action_search" /> </menu> @Override public boolean onCreateOptionsMenu(Menu menu) { /*menu.add(Menu.NONE, PREF_ID, Menu

How to change toolbar menu item text color for pre Lollipop and Lollipop versions

六眼飞鱼酱① 提交于 2019-12-01 08:51:58
问题 I am using Toolbar for the purpose of material design in my application. Everything working fine but except when it comes to change the menu item text color I am completely stuck up with the solution. I am also posting screenshot of the text that should be taken and code I am using in my application for your reference. I tried several alternate methods like assigning as follows <item name="android:actionMenuTextColor">@color/white</item> <item name="android:textColor">#000</item> But known of

Activate CAB menu when OnClickEvent happens in Android

耗尽温柔 提交于 2019-12-01 06:52:16
Trying to activate CAB menu when clicking on MenuItem from ActionBar. Here is how I set the GridView for listening to Multi Choice. The multiModeChoiceListener is working fine when I long press on Any item in the GridView. It is working fine. Now I have a requirement to activate the CAB menu when do press on a menu item in Action Bar. Once it is pressed, the CAB menu should read that 0 items are selected. After that it should allow me to select items from GridView on single clicks. How can I achieve this feature? GridView set listener: gv.setChoiceMode(GridView.CHOICE_MODE_MULTIPLE_MODAL); gv

searchManager.getSearchableInfo(getComponentName()) returns null

微笑、不失礼 提交于 2019-12-01 03:33:02
I've followed this Android guide in order to add a search bar to an activity. The setup looks like this: res/menu/activity_main.xml: <?xml version="1.0" encoding="utf-8"?> <menu xmlns:android="http://schemas.android.com/apk/res/android" > <item android:id="@+id/search" android:title="@string/menu_search" android:icon="@android:drawable/ic_menu_search" android:showAsAction="collapseActionView|ifRoom" android:actionViewClass="android.widget.SearchView" /> <item android:id="@+id/menu_settings" android:orderInCategory="100" android:showAsAction="never" android:title="@string/menu_settings" android