menuitem

Handling a Menu Item Click Event - Android

落花浮王杯 提交于 2019-11-26 15:10:39
I want to create an intent that starts a new activity once a Menu Item is clicked, but I'm not sure how to do this. I've been reading through the android documentation, but my implementation isn't correct..and some guidance in the right direction would help. I've listed my code below and commented out my problem areas, I think I'm invoking the wrong method. package com.jbsoft.SimpleFlashlight; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.view.*; import android.view.MenuItem.OnMenuItemClickListener; import android.widget.Button; import

Android - How to dynamically change menu item text outside of onOptionsItemsSelected or onCreateOptionsMenu

走远了吗. 提交于 2019-11-26 14:11:10
I'm trying to change the title of a menu item from outside of the onOptionsItemSelected(MenuItem item) method. I already do the following; public boolean onOptionsItemSelected(MenuItem item) { try { switch(item.getItemId()) { case R.id.bedSwitch: if(item.getTitle().equals("Set to 'In bed'")) { item.setTitle("Set to 'Out of bed'"); inBed = false; } else { item.setTitle("Set to 'In bed'"); inBed = true; } break; } } catch(Exception e) { Log.i("Sleep Recorder", e.toString()); } return true; } however I'd like to be able to modify the title of a particular menu item outside of this method. Charles

Android adding a submenu to a menuItem, where is addSubMenu()?

萝らか妹 提交于 2019-11-26 13:05:51
问题 I want to add a submenu inside my OptionsMenu to a menuItem, programatically according to my parameters. I\'ve checked \"MenuItem\" in android sdk and there is no addSubMenu() method!, although you can find \"hasSubMenu()\" and \"getSubMenu\". Was thinking on doing this in onCreateOptionsMenu: public boolean onCreateOptionsMenu(Menu menu) { MenuItem mi = menu.getItem(MYITEMID); // << this is defined in my XML optionsMenu SubMenu subm = mi.addSubMenu(0,1,0,\"Map 1\"); // no addSubMenu() method

Mutually exclusive checkable menu items?

微笑、不失礼 提交于 2019-11-26 12:11:10
问题 Given the following code: <MenuItem x:Name=\"MenuItem_Root\" Header=\"Root\"> <MenuItem x:Name=\"MenuItem_Item1\" IsCheckable=\"True\" Header=\"item1\" /> <MenuItem x:Name=\"MenuItem_Item2\" IsCheckable=\"True\" Header=\"item2\"/> <MenuItem x:Name=\"MenuItem_Item3\" IsCheckable=\"True\" Header=\"item3\"/> </MenuItem> In XAML, is there a way to create checkable menuitem\'s that are mutually exclusive? Where is the user checks item2, item\'s 1 and 3 are automatically unchecked. I can accomplish

How to change the Text color of Menu item in Android?

放肆的年华 提交于 2019-11-26 11:35:52
Can I change the background color of a Menu item in Android? Please let me know if anyone have any solution to this. The last option will be obviously to customize it but is there any way for changing the text color without customizing it. One simple line in your theme :) <item name="android:actionMenuTextColor">@color/your_color</item> Marcus Wolschon It seems that an <item name="android:itemTextAppearance">@style/myCustomMenuTextAppearance</item> in my theme and <style name="myCustomMenuTextAppearance" parent="@android:style/TextAppearance.Widget.IconMenu.Item"> <item name="android:textColor

Android : Get view Reference to a Menu Item

。_饼干妹妹 提交于 2019-11-26 11:00:38
问题 I plan to use quick actions UI pattern in my application. Android Quick Actions UI Pattern . The quick action window needs a pivot view to stick to. quickAction.show(View pivotView); I intend to use quick action for the menu Item, I can get access to the item that is clicked. But the problem is i need to reference a view from the menu item so that i can pass it to the quick action. How can i get reference to a view in the menuItem that is selected. 回答1: You can achieve this by providing your

How to display menu item with icon and text in AppCompatActivity

自闭症网瘾萝莉.ら 提交于 2019-11-26 09:39:22
问题 I tried different combinations in xml file: <menu xmlns:android=\"http://schemas.android.com/apk/res/android\" xmlns:app=\"http://schemas.android.com/apk/res-auto\" xmlns:tools=\"http://schemas.android.com/tools\" tools:context=\".MainActivity\"> <item android:id=\"@+id/action_create_alarm\" android:icon=\"@drawable/ic_action_accept\" android:orderInCategory=\"100\" android:title=\"@string/menu_create_alarm\" app:showAsAction=\"ifRoom|withText\" /> </menu> or <menu xmlns:android=\"http:/

WPF - How can I create menu and submenus using binding

放肆的年华 提交于 2019-11-26 09:29:06
问题 I am trying to create a dynamic menu using binding. I my viewmodel I have a list of objects which contains an header and a command. However, it is not working. I think the problem is in the data template. See my code below: <Menu Background=\"{x:Null}\" Grid.Row=\"0\" Grid.Column=\"1\" Panel.ZIndex=\"2\" Width=\"865\" Height=\"85\" HorizontalAlignment=\"Left\" ItemsSource=\"{Binding Path=MenuItems}\"> <Menu.ItemTemplate> <HierarchicalDataTemplate DataType=\"MenuItemViewModel\" ItemsSource=\"

How can I dynamically create menu items?

六月ゝ 毕业季﹏ 提交于 2019-11-26 07:28:07
问题 I\'m building an Android application and I\'m trying to build a user management system where users can login, logout, etc. I want to display a login menu item if the user is logged out and a logout button if the user is logged in. How can I do this dynamically? This is the layout file right now: <?xml version=\"1.0\" encoding=\"utf-8\"?> <menu xmlns:android=\"http://schemas.android.com/apk/res/android\"> <item android:id=\"@+id/add\" android:title=\"Add\" android:icon=\"@drawable/ic_menu_add\

Android 4.3 menu item showAsAction=“always” ignored

随声附和 提交于 2019-11-26 06:14:59
I'm using the new v7 appcompat library available starting from Android 4.3 (API level 18). Regardless of what is specified in showAsAction for a menu item, it's not shown - it always creates the overflow menu icon, and puts even a single menu item under the menu. Trying to add menu to an activity like this: @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.menu_sizes, menu); return true; } And here's my menu xml: <menu xmlns:android="http://schemas.android.com/apk/res/android"> <item android:id="@+id/menu_add_size" android:title="@string/menu_add_item"