android-menu

Item with app:showAsAction not showing

拥有回忆 提交于 2019-11-26 08:15:59
问题 I can\'t understand why wrong and incompatible (AndroidStudio tells me \"Should use app:showAsAction with the appcompat library) code <menu xmlns:android=\"http://schemas.android.com/apk/res/android\" > <item android:id=\"@+id/action_search\" android:title=\"@string/action_search\" android:icon=\"@drawable/search\" android:showAsAction=\"always\" /> </menu> works perfect, but proper and compatible version like <menu xmlns:android=\"http://schemas.android.com/apk/res/android\" xmlns:app=\"http

Android, How to create option Menu

北城以北 提交于 2019-11-26 08:09:15
问题 Here I tried to make option menu, but menu is not displaying on screen, so please guide me where am I doing mistake... MenuTest.java public class MenuTest extends Activity { @Override public boolean onCreateOptionsMenu(Menu menu) { MenuInflater inflater=getMenuInflater(); inflater.inflate(R.menu.more_tab_menu, menu); return super.onCreateOptionsMenu(menu); } @Override public boolean onOptionsItemSelected(MenuItem item) { switch(item.getItemId()) { case R.id.feeds: break; case R.id.friends:

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\

PopupWindow - Dismiss when clicked outside

蓝咒 提交于 2019-11-26 06:05:54
问题 I have a PopupWindow on my activity, the thing is my PopupWindow still shows even when I\'m interacting with my activity (say scrolling on my list). I can scroll through my list and the PopupWindow is still there. What I want to achieve is when I\'m touching/scrolling/clicking/etc on the screen which is not the PopupWindow, I want to dismiss the PopupWindow. Just like how a menu works. If you clicked outside of the menu, the menu will be dismissed. I\'ve tried setOutsideTouchable(true) but it

Android custom dropdown/popup menu

生来就可爱ヽ(ⅴ<●) 提交于 2019-11-26 04:35:24
问题 How do I do a custom dropdown/popup menu anchored to a button? I need it to work like the popup menu (anchored to a view), and do something when I click an item from the menu. How do I add items to the menu by code, keeping menu\'s height and make it scrollable if there are more than 5 items. I don\'t need to add any images, just text. 回答1: To create popup menu in android. activity_main.xml It contains only one button. File: activity_main.xml <RelativeLayout xmlns:android="http://schemas

How do I hide a menu item in the actionbar?

夙愿已清 提交于 2019-11-26 03:25:11
问题 I have an action bar with a menuitem. How can I hide/show that menu item? This is what I\'m trying to do: MenuItem item = (MenuItem) findViewById(R.id.addAction); item.setVisible(false); this.invalidateOptionsMenu(); 回答1: Get a MenuItem pointing to such item, call setVisible on it to adjust its visibility and then call invalidateOptionsMenu() on your activity so the ActionBar menu is adjusted accordingly. Update: A MenuItem is not a regular view that's part of your layout. Its something

How do I hide a menu item in the actionbar?

橙三吉。 提交于 2019-11-26 02:48:44
I have an action bar with a menuitem. How can I hide/show that menu item? This is what I'm trying to do: MenuItem item = (MenuItem) findViewById(R.id.addAction); item.setVisible(false); this.invalidateOptionsMenu(); K-ballo Get a MenuItem pointing to such item, call setVisible on it to adjust its visibility and then call invalidateOptionsMenu() on your activity so the ActionBar menu is adjusted accordingly. Update: A MenuItem is not a regular view that's part of your layout. Its something special, completely different. Your code returns null for item and that's causing the crash. What you need

Android: customize application&#39;s menu (e.g background color)

試著忘記壹切 提交于 2019-11-26 02:00:32
问题 What is the way (if there is a way) to customize the menu (the one triggered by the MENU button of the phone). I\'m especially interested in two things: changing the background color from the standard light gray into a darker gray how the menu items are aligned. I have 4 items and they are automatically aligned 2x2, but I would prefer to have them all in one line (1x4) 回答1: Not with the built-in menu framework. You are welcome to intercept the MENU button (via onKeyDown() or something) and

How to change the background color of Action Bar&#39;s Option Menu in Android 4.2?

徘徊边缘 提交于 2019-11-26 00:22:21
问题 I\'d like to change the background color of the option (overflow) menu in Android 4.2. I have tried all the methods but it is still showing the default color set by the theme. I used the following code & XML configs. MainActivity.java public class MainActivity extends Activity { @SuppressLint(\"NewApi\") @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); getActionBar().setIcon(R.drawable.ic_launcher);