android-menu

dismiss popup when options menu is pressed

老子叫甜甜 提交于 2019-12-11 08:09:26
问题 I implemented a popup which shows up when I press the hardware menu key. Now I want to dismiss the popup when I press on the menu key again. I tried this @Override public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_MENU) { if (pw.isShowing()) { pw.dismiss(); } else { openpopup(); } return true; } return super.onKeyDown(keyCode, event); } here's the open popup method public void openpop() { View view1 = getCurrentFocus(); showpopup(view1); } here's the

Android Vertical Menu

人走茶凉 提交于 2019-12-11 03:34:21
问题 I would like to create a menu to appear on the screen when the Menu button is pressed.I've implemented it and it appears in the bottom of the page but not the one i would like... Hereunder my code and my goal picture to achieve public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } @Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId(

How to implement a menuitem click listener inside a fragment in android

血红的双手。 提交于 2019-12-10 22:56:06
问题 I have MenuItems in the ActionBar and I am using Fragments inside ViewPager. Now I would like to handle onMenuItemClickListener event inside my fragment. It works fine inside Main Activity. But not inside Fragments. And also it doesn't fetch any error. Here is the methods that I tried. Both works fine inside Activity. First method: public boolean onCreateOptionsMenu(Menu menu) { MenuItem item = menu.findItem(R.id.grid_view); item.setOnMenuItemClickListener(new OnMenuItemClickListener() {

I am having a java.lang.unsupportedoperationexception in Android Studio

余生颓废 提交于 2019-12-10 22:37:40
问题 public boolean onOptionsItemSelected(MenuItem item){ int id = item.getItemId(); switch(id){ case R.id.jaren_3de: updateKlassenList(klassen); break; case R.id.jaren_4de: updateKlassenList(klassen2); break; case R.id.jaren_5de: updateKlassenList(klassen3); break; case R.id.jaren_6de: updateKlassenList(klassen4); break; // case R.id. } return super.onOptionsItemSelected(item); } private void updateKlassenList(String[] data) { klassenList.clear(); klassenList.addAll(Arrays.asList(data)); // I

How to set a typeface to menu items in overflow menu on toolbar

牧云@^-^@ 提交于 2019-12-10 22:13:34
问题 I want to change the default typeface of the items of the overflow menu and set a custom typeface . I tried adding a Factory to the LayoutInflater and within the onCreateView() method I changed the TextView's typeface . But it didn't work. Here is the code(Inside onCreateOptionsMenu), getLayoutInflater().cloneInContext(this).setFactory(new LayoutInflater.Factory() { @Override public View onCreateView(String name, Context context, AttributeSet attrs) { if (name.contains("com.android.internal

Change custom SubMenu background color with Java code

狂风中的少年 提交于 2019-12-10 20:54:23
问题 In my home activity, I have a toolbar with a custom Overflow menu and I want it to change color to be accorded with toolbar background color (cause toolbar background color can change (user changes to his own favorite color))...I don't know how to do it : Here's my overflow_menu.xml : <menu xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto"> <item android:id="@+id/overflow_save_current" app:showAsAction="always" android:title="

Options Menu not displaying on ActionBar

亡梦爱人 提交于 2019-12-10 20:02:41
问题 I wanted to display Menu in ActionBar using ActionBarActivity . I am getting options menu while clicking options button instead of displaying in the top of action bar. I need the options menu at top instead of clicking the options menu from 2.3 onwards My Code : public class MainActivity extends ActionBarActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); ActionBar actionBar = getSupportActionBar

How to hide or add menu items for Flavor?

做~自己de王妃 提交于 2019-12-10 18:19:40
问题 I have an app that has 3 different flavors, full , part1 and part2 . All different flavors have different package names, so I can ship them as different apps. Now I want that only part1 gets a menu item called Reload . The other 2 flavors shouldn't have this menu item. Is this possible? I tried the following with the menu resources: app | +-src | +-full | +-main | | | +-res | | | +-menu | | | +-main_activity.xml | +-part1 | | | +-res | | | +-menu | | | +-main_activity.xml | +-part2 Where main

Android application icon changes with runtime

牧云@^-^@ 提交于 2019-12-10 18:08:41
问题 In my app I want to display different icons for the application. Changes should be according to the scenario. For example, it will mark the number of days remaining for the task completion. On the android menu this icon will display the number of days remaining. If anyone has any idea for this, I would appreciate it. Thanks. 回答1: As far as i know, you cant. Also refer to this answer: Android Application Icon Change 回答2: I am afraid you can't change your app's icon programmatically. How to

finditem() doesn't find menu, stuck with NullPointerException

时光毁灭记忆、已成空白 提交于 2019-12-10 17:52:11
问题 I'm stuck while changing some properties on my options menu at onCreateOptionsMenu() . It seems like findItem() returns null, even though I'm pretty sure that the reference to the menu item is correct. My code looks as follows: @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.activity_profile, menu); MenuItem leftie = menu.findItem(R.id.menu_profile); leftie.setIcon(R.drawable.ic_menu_mapmode); leftie.setTitle(R.string.back_map); leftie.setIntent