android-menu

android menu code not working

六眼飞鱼酱① 提交于 2019-11-29 18:55:11
I have been trying to figure out why my boolean is not changing when I press the button, when I changed it manually it worked, but it doesn't do any thing. I have tried to follow tutorials to the word but they don't work. Can anybody point out where I am going wrong? public boolean onOptionsItemSelected(MenuItem menu) { MenuItem freeze = (MenuItem)findViewById(R.id.freeze); // Handle item selection switch (menu.getItemId()) { case R.id.freeze: if (freze == false){ freze = true; } else { freze = false; } return true; case R.id.toggleVolCount: if (toggleVol == true){ toggleVol = false; } else {

create new menuInflater or getMenuInflater() from activity?

 ̄綄美尐妖づ 提交于 2019-11-29 18:53:01
问题 I'm creating new option menu inside fragment but after reading http://developer.android.com/resources/articles/avoiding-memory-leaks.html which said to it's better to use context-application than context-activity, I'm afraid to use getActivity().getMenuInflater() So, actually which one better @Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { MenuInflater mInflater = new MenuInflater(getActivity().getApplicationContext()); mInflater.inflate(R.menu.simple_menu, menu)

Toolbar back button is not calling onOptionsItemSelected Android

微笑、不失礼 提交于 2019-11-29 18:24:44
I can able to see the back button in the toolbar but when i click, nothing happens. It is not going to onOptionsItemSelected but when i remove the whole implementation of ActionBarDrawerToggle then the back button is working fine. I need to switch between both when i needed. Thank in advance. package demo.sample.com.sample.base; public class MainActivity extends AppCompatActivity { private static final String TAG = MainActivity.class.getSimpleName(); private DrawerLayout mDrawer; private ActionBarDrawerToggle mDrawerToggle; @Override protected void onCreate(Bundle savedInstanceState) { super

Custom AppCompat Theme not changing Overflow icon on older devices

半城伤御伤魂 提交于 2019-11-29 16:57:46
Recently I decided to change the Action Overflow Icon on my app. I got it working on Lollipop devices, but it isn't working on my Ice Cream Sandwich and Kitkat device. Note: on both the devices that it does not work on, the action overflow icon has 3 rounded dots, so the theme is changing it to the Material version....just not my version. My issue is that I cannot get this to work on older devices, but it works on Lollipop. Before, I would have had to create separate themes for each version, but now that is not needed. Only one theme is recommended. Code <resources> <!-- Base application theme

Android menu line break

主宰稳场 提交于 2019-11-29 12:44:22
I have the following Android menu XML file: <?xml version="1.0" encoding="utf-8"?> <menu xmlns:android="http://schemas.android.com/apk/res/android"> <item android:id="@+id/programma" android:icon="@android:drawable/ic_menu_agenda" android:title="@string/programma" /> <item android:id="@+id/settings" android:icon="@android:drawable/ic_menu_preferences" android:title="@string/settings" /> <item android:id="@+id/help" android:icon="@android:drawable/ic_menu_help" android:title="@string/help" /> </menu> That gives me three menu buttons on one line. However, I want to divide them in two lines, with

How to implement dynamic values on menu item in Android [duplicate]

筅森魡賤 提交于 2019-11-29 12:25:25
问题 This question already has an answer here: How to get text on an ActionBar Icon? 4 answers I have a menu item in the action bar. Along with the menu item image, I need to show some number associated with it which will change often. I am not using Action bar sherlock. I don't want to use that. Other than this everything else just works fine. In the shown image, the white icon color icon is mine. I need to generate the number with the red color background dynamically. How can I do that in

How can I focus on a collapsible action view EditText item in the action bar (when it is expanded) and force the soft keyboard to open?

不想你离开。 提交于 2019-11-29 11:51:21
问题 I am using Jake Wharton's excellent ActionBarSherlock library and have a collapsible search action view. I want to popup the soft keyboard when the search action view is expanded. We can read a recommended way of doing this in a DialogFragment in the "Using DialogFragments" blog post by Google (altered a bit for readability). // Show soft keyboard automatically mEditText.requestFocus(); int mode = WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE; getDialog().getWindow().setSoftInputMode

showAsAction = “always” is ignored in Toolbar

ぐ巨炮叔叔 提交于 2019-11-29 11:01:48
After switching to toolbar there is a problem with menu icons. Although I set for a menu item android:showAsAction="always" it does not show the icon, I can only find it clicking on the popup icon. This is myActivity public class myActivity extends AppCompatActivity{ ......... public void onCreate(....){ ............. Toolbar toolbar = (Toolbar) findViewById(....); setSupportActionBar(toolbar); } ............ public boolean onCreateOptionsMenu(Menu menu{ getMenuInflater().inflate(R.menu.menu, menu); return super.onCreateOptionsMenu(menu); } ............. } menu.xml <menu xmlns:android="http:/

Enable/Disable ActionBar Menu Item

风格不统一 提交于 2019-11-29 10:56:30
问题 I have actionbar menuitems cancel and save. menu.xml <?xml version="1.0" encoding="utf-8"?> <menu xmlns:android="http://schemas.android.com/apk/res/android" > <item android:id="@+id/saveButton" android:showAsAction="always" android:title="@string/save" android:visible="true"> </item> <item android:id="@+id/cancelButton" android:showAsAction="always" android:title="@string/cancel" android:visible="true"> </item> </menu> I want to disable save menuitem when activity is started. My activity code

How to programmatically trigger/click on a MenuItem in Android?

久未见 提交于 2019-11-29 10:54:31
问题 I have these menu items in my menu_main.xml <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_restart" android:title="Restart" android:orderInCategory="1" /> <item android:id="@+id/action_clear" android:title="Clear" android:orderInCategory="2" /> <item android:id="@+id/action_update" android:title="Update" android