android-optionsmenu

How to change Toolbar navigation icon and options menu margin

旧城冷巷雨未停 提交于 2019-12-17 21:56:27
问题 Is there any way to change the left margin of the Navigation icon and the right margin of the Action items in Toolbar ? 回答1: I went through the Toolbar source code to find a solution and it turned out to be pretty simple. Toolbar uses two styles to style the toolbar and the navigation icon. Just had to override those styles with my own. <style name="myToolbarNavigationButtonStyle" parent="@style/Widget.AppCompat.Toolbar.Button.Navigation"> <item name="android:minWidth">0dp</item> <item name=

Android options menu icon won't display

眉间皱痕 提交于 2019-12-17 06:48:08
问题 I'm following a book on Android Development to get myself started writing my first real app. I got up to the point where I'm making an options menu for one of my activities. The menu shows up, but the corresponding icon of the menu item refuses to display. Here is the code for the menu: ReminderListActivity @Override public boolean onCreateOptionsMenu(Menu menu) { super.onCreateOptionsMenu(menu); MenuInflater mi = getMenuInflater(); mi.inflate(R.menu.list_menu, menu); return true; } res/menu

How to add Action bar options menu in Android Fragments

若如初见. 提交于 2019-12-17 06:33:21
问题 I am trying to have a options menu in Android Fragments . ActionBar options menu are not displaying in my Fragments. Here is my code and I have both onCreateOptionsMenu() and onOptionSelected() function. My code doesn't shows any error. But options menu are not displaying. package org.reachout; import android.os.Bundle; import android.support.v4.app.Fragment; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.LinearLayout; import

How to add Action bar options menu in Android Fragments

♀尐吖头ヾ 提交于 2019-12-17 06:33:10
问题 I am trying to have a options menu in Android Fragments . ActionBar options menu are not displaying in my Fragments. Here is my code and I have both onCreateOptionsMenu() and onOptionSelected() function. My code doesn't shows any error. But options menu are not displaying. package org.reachout; import android.os.Bundle; import android.support.v4.app.Fragment; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.LinearLayout; import

How to add Options Menu to Fragment in Android

本小妞迷上赌 提交于 2019-12-17 02:01:03
问题 I am trying to add an item to the options menu from a group of fragments. I have created a new MenuFragment class and extended this for the fragments I wish to include the menu item in. Here is the code: public class MenuFragment extends Fragment { MenuItem fav; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setHasOptionsMenu(true); } public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { fav = menu.add("add"); fav.setIcon(R

Use same method for all option menu in whole Application Android

[亡魂溺海] 提交于 2019-12-13 09:13:46
问题 I have 10 to 12 Activity , All Activity has Help Menu as an Option Menu . I am succeed with following code to create it and showing help on click of them. Intent intent = new Intent(); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.setAction(Intent.ACTION_VIEW); intent.setDataAndType(Uri.fromFile(new File(cacheDir, "HELP.pdf")),"application/pdf"); context.startActivity(intent); But I want to Reduce this code for all Activity, and for that i have created one class and make one method

Creating Options menu in Android

白昼怎懂夜的黑 提交于 2019-12-12 13:50:20
问题 I am trying to create options menu in my Android program. I am using the following code to inflate options menu : @Override public boolean onCreateOptionsMenu(Menu menu) { super.onCreateOptionsMenu(menu); MenuInflater inflater=getMenuInflater(); inflater.inflate(R.menu.optionsmenu, menu); return true; } And my xml code is : ?xml version="1.0" encoding="utf-8"?> <menu xmlns:android="http://schemas.android.com/apk/res/android"> <item android:id="@+id/Option1" android:title="Option1"/> <item

Option Menu does not appear in Android

 ̄綄美尐妖づ 提交于 2019-12-12 07:27:02
问题 I have this code to create the menu: @Override public boolean onCreateOptionsMenu(Menu menu) { super.onCreateOptionsMenu(menu); MenuInflater inflater = getMenuInflater(); inflater.inflate(R.menu.tip_menu, menu); return true; } @Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case MNU_PREV: animateTextViewsPrev(); break; case MNU_NEXT: animateTextViewsNext(); break; } return true; } And the XML: <?xml version="1.0" encoding="utf-8"?> <menu xmlns

popup window from android options menu not working

柔情痞子 提交于 2019-12-12 05:28:32
问题 Actually I am showing popup window(custom layout) when options menu item clicked and my options menu are bottom to the screen(splitActionBarWhenNarrow).I am getting some exception please help me code: switch (item.getItemId()) { case R.id.redid: Toast.makeText(MainActivity.this,"red color", Toast.LENGTH_SHORT).show(); break; case R.id.blueid: Toast.makeText(MainActivity.this,"blue color", Toast.LENGTH_SHORT).show(); break; case R.id.greenid: LayoutInflater inflater=(LayoutInflater)

Changing visibility of menu items in fragment

亡梦爱人 提交于 2019-12-12 04:45:43
问题 I'm trying to hide some menu items when a fragment is changed, but seems that this is not working. Here is what im doing: Defining the menu and menu items: @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu items for use in the action bar MenuInflater inflater = getMenuInflater(); inflater.inflate(R.menu.actionbar_sharecall, menu); actionMenu = menu; MenuItem searchItem = menu.findItem(R.id.action_searchmenuitem); MenuItem item = menu.findItem(R.id.action_menushare)