android-menu

Action Buttons do not cover the entire Toolbar

末鹿安然 提交于 2020-01-04 05:59:54
问题 I have used a Toolbar to display four action buttons. When I inflate the toolbar with menu, the action buttons are displayed towards one side as shown in the picture : How can I make these action buttons cover the entire toolbar? This is the code for the Activity : public class ResultActivity extends FragmentActivity { final int TAB_NUM = 2; private ViewPager mViewPager; private PagerAdapter mPagerAdapter; private Toolbar mResultToolbar; @Override protected void onCreate(Bundle

How can we use menu items outside onOptionItemSelected like in onCreate()

﹥>﹥吖頭↗ 提交于 2020-01-04 04:46:07
问题 I am facing a problem in getting a reference to a menu item outside onOptionsItemSelected() method. I want that part of code to be executed as soon as my Activity is created, so I am trying to use that menu item in onCreate() but it is always returning null . Any help would be greatly appreciated. I am trying the following code: private Menu menu; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_sub_task_detail

How to programmatically set the margin between icon and title of menu item of Navigation Drawer in Android?

时光毁灭记忆、已成空白 提交于 2020-01-03 05:42:06
问题 I am developing an Android App. In my app, I am using navigation drawer and navigation view. But I set the menu item for them programmatically. For a menu item, I set both icon and title. But I am having a problem with that. That is I cannot set the spacing between icon and title that I programmatically added to menu. This is how I programmatically add item to menu Menu menu = leftDrawer.getMenu(); SubMenu subMenu = menu.addSubMenu(MAIN_MENU_ITEM_GROUP_ID, 99, 99, "Others"); subMenu.add(MAIN

How to set specific listeners for varying popup menus ? (code inside)

邮差的信 提交于 2020-01-03 02:54:17
问题 I am working on an app which has in one of its activity a "Filter Button" with a popup menu appearing everytime you click on it. The particular thing is that this popup menu is not always the same, it can vary depending on what the user does in the previous activity. So far, I have coded the part which allows the app to display different popup menu in different cases (it works well). Now, I am stuck trying to add individual listeners for any of these cases. Here is my code with some

How to set specific listeners for varying popup menus ? (code inside)

醉酒当歌 提交于 2020-01-03 02:53:07
问题 I am working on an app which has in one of its activity a "Filter Button" with a popup menu appearing everytime you click on it. The particular thing is that this popup menu is not always the same, it can vary depending on what the user does in the previous activity. So far, I have coded the part which allows the app to display different popup menu in different cases (it works well). Now, I am stuck trying to add individual listeners for any of these cases. Here is my code with some

Alternate to hasPermanentMenuKey() for Android 2.3.3

≡放荡痞女 提交于 2020-01-03 01:41:07
问题 I am building my App with API level 10. But it can be installed and used in later versions. I need to show Action Bar only if the device does not have menu button. For Example, Tablets, Google Galaxy Nexus Phone, etc. People suggest to use hasPermanentMenuKey() function. But it is available only after API level 14 I guess. Can anyone suggest me how to get around this issue? Thanks, Karthik 回答1: Use Below code : ViewConfiguration.get(context).hasPermanentMenuKey(); First set your build target

Changing default text colour and still showing disabled menu items in different colour

a 夏天 提交于 2020-01-01 12:35:19
问题 With Theme.Holo.Light as the base theme, a designer noticed that the default text colour is not black, but a dark grey ( #505050 ). We'd like to change it to black. Looking for a simple way to change the default to black everywhere in the app, I found that this works: <resources> <style name="MyAppTheme" parent="android:Theme.Holo.Light"> <item name="android:textColor">@android:color/black</item> </style> </resources> Now, problem is , that also changes the colour of disabled items in Action

Activate CAB menu when OnClickEvent happens in Android

一个人想着一个人 提交于 2019-12-30 10:03:12
问题 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

ListFragment onPrepareOptionsMenu called before onCreate. Why and How to Fix / Bypass?

点点圈 提交于 2019-12-30 08:34:29
问题 Okay, so I've got FavoritesList extending GalleryList which extends ListFragment: public static class FavoritesList extends GalleryList { public static FavoritesList newInstance(int page) { FavoritesList list = new FavoritesList(); Bundle args = new Bundle(); args.putInt("page", page); list.setArguments(args); return list; } @Override public void onCreate(Bundle saveInstanceState) { super.onCreate(saveInstanceState); Cursor cursor = dbHelper.getGalleries(fav, preferences.getString("sort"+fav,

How to add submenu items to NavigationView programmatically instead of menu xml

喜欢而已 提交于 2019-12-30 02:17:27
问题 I'm trying to add submenu items to NavigationView programmatically . I'm able to add items into menu but not into submenu Adding items to menu works Menu menu = mNavigationView.getMenu(); menu.add(Menu.NONE, Menu.NONE, index, "Menu Item1"); But adding items to sub menu doesn't work Menu menu = mNavigationView.getMenu(); SubMenu subMenu = menu.addSubMenu("Sub menu title"); subMenu.add(Menu.NONE, Menu.NONE, index, "SubMenu Item1"); 回答1: The trick to call BaseAdapter.notifyDataSetChanged on the