android-menu

How to add title in Navigation drawer layout?

烈酒焚心 提交于 2019-11-28 16:19:40
问题 [UPDATE] I solve the problem by adding addHeaderView : protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mTitle = mDrawerTitle = getTitle(); mPlanetTitles = getResources().getStringArray(R.array.planets_array); mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); mDrawerList = (ListView) findViewById(R.id.left_drawer); LayoutInflater inflater = getLayoutInflater(); ViewGroup mTop = (ViewGroup)inflater

android menu code not working

安稳与你 提交于 2019-11-28 13:00:24
问题 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

anchor popup menu over overflow button

拥有回忆 提交于 2019-11-28 12:25:19
I'm trying to create a custom popup menu that I would like to position on the overflow menu button of the actionbar (am using a Toolbar with setSupportActionBar() for this if it matters). I found out that this can be done with the setAnchorView() (from reading Custom Menu item in Overflow menu ). However I cant seem to figure out how to retrieve the overflow menu as a view (that I could use to set the anchor with). Also I did try anchoring this to the parent layout of the activity itself but it showed up on the left top, and the height of the menu was equal to the height of the actionbar

How to set a long click listener on a MenuItem (on a NavigationView)?

一个人想着一个人 提交于 2019-11-28 12:02:21
How can I set a long click listener on a MenuItem ? I tried this answer , but the method doesn't exist for me. Any solutions? Code: Menu menu = navigationView.getMenu(); MenuItem menuItem = menu.findItem(R.id.menu_item); // TODO set a long click listener on the menuItem. menuItem.setOnLongClickListener(...); // Method does not exist, any other solutions? Edit: I don't want to set a custom ActionView, I want the long click listener to the whole MenuItem , without a custom View. one of many ways (assuming we use Toolbar) - this example should give you the idea how to implement long click on

Toolbar back button is not calling onOptionsItemSelected Android

大憨熊 提交于 2019-11-28 11:50:34
问题 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

Reuse the Action Bar in all the activities of app

删除回忆录丶 提交于 2019-11-28 11:27:06
I am a newbie to android and I was wondering if someone could guide me about how to reuse the action bar in all of my android activities. As far as I have explored, I found out that we have to make a BaseActivity class and extend it in our Activity where we want to reuse it, and also we have to make a xml layout and include it in our activity xml file. I have finished with the BaseActivity part. Now I am sort of confused in framing the xml part and including it. I know how to merge and include a layout, But in case of Action Bar, what necessary steps are to be taken. Any help would be

Custom AppCompat Theme not changing Overflow icon on older devices

蓝咒 提交于 2019-11-28 10:45:36
问题 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,

How change position of popup menu on android overflow button?

半城伤御伤魂 提交于 2019-11-28 09:24:58
I just like to implement somethings same as popup menu in the Gmail app, anchored to the overflow button at the top-right. for that I used the same code as google tutorial for android Android popup menu , but for me show pop menu on top of edge of actionbar not under that. If you notice on pop menu of gmail overflow you saw that popmenu take place at edge of actionbar. This is the xml that I used for popup menu: <menu xmlns:android="http://schemas.android.com/apk/res/android" > <item android:id="@+id/item1" android:title="lablab"/> <item android:id="@+id/item2" android:title="lablab"/> </menu>

android.support.v7 with `ActionBarActivity` no menu shows

蓝咒 提交于 2019-11-28 04:52:44
In the new update Google has released a new API support library, that supports the ActionBar in API level 7+. I used ActionBarSherlock until this update and I wrote the code to load the menu: @Override public boolean onCreateOptionsMenu(Menu menu) { MenuInflater inflater = getMenuInflater(); inflater.inflate(R.menu.activity_main, menu); return true; } and the menu file: <?xml version="1.0" encoding="utf-8"?> <menu xmlns:android="http://schemas.android.com/apk/res/android"> <item android:id="@+id/item_menu_ok" android:icon="@drawable/ic_action_ok" android:title="@string/ok" android:showAsAction

showAsAction = “always” is ignored in Toolbar

こ雲淡風輕ζ 提交于 2019-11-28 04:26:39
问题 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,