menuitem

How to create a Menu instance programmatically? i.e. inflate a Menu outside onCreateOptionsMenu

放肆的年华 提交于 2019-12-02 20:10:24
I want to inflate a menu object outside onCreateOptionsMenu method (which means to create/show the menu when the user doesn't press the button), so I need to create a menu instance to pass it to the inflate method. Here is an example of what I am trying to achieve: Menu menu = // How to create an instance !? new MenuInflater(context).inflate(R.menu.my_menu, menu) Menu is an interface, so I need to know which class is implementing it. I did browse Android code to get any hint on how a Menu object is created, but still could not find what I am looking for. Edit 1 My goal is to fire an

What should I pass for root when inflating a layout to use for a MenuItem's ActionView?

青春壹個敷衍的年華 提交于 2019-12-02 20:06:45
I have an ImageView that I attach to a MenuItem as its ActionView (the item appears in the ActionBar ). The layout for this view comes from XML. I'm inflating it like so: ImageView actionView = (ImageView) layoutInflater.inflate( R.layout.action_view_layout, null); This appears to work fine. However; passing null for root in the call to inflate() makes Lint yell at me: Avoid passing null as the view root (need to resolve layout parameters on the inflated layout's root element) I can seemingly manage without a root in my specific case, but I'd rather have the code be as correct as possible. The

How to set icon color of MenuItem?

荒凉一梦 提交于 2019-12-02 16:59:10
I defined a menu item that has ShareActionProvider and share white icon like so : <item android:icon="@drawable/ic_share_white_24dp" android:id="@+id/action_share" android:title="@string/action_share" android:orderInCategory="200" app:showAsAction="ifRoom" app:actionProviderClass="android.support.v7.widget.ShareActionProvider"/> But when I launch the application, I get a different black share icon. How to set the share icon to be white? Here is the result that I have This is a theming issue. Depending on your current theme, you need to set the correct ActionBar overlay theme. The Action

Android Change Navigation Drawer Menu Items Text programmatically

我是研究僧i 提交于 2019-12-02 16:36:48
I have the new Navigation Drawer in my app and I want to change the navigation view menu items title text dynamically from code. I have watched many posts but I can't figure out, how can I do this. How can I achieve this correctly? MainActivity.java @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab); fab.setOnClickListener(new View.OnClickListener() {

java.lang.NullPointerException when try listview.getChildAt()

≡放荡痞女 提交于 2019-12-02 14:55:16
问题 There is ListView with correct values: public class FragmentTab1 extends SherlockFragment { ListView list; LazyAdapter adapter; @Override public void onViewCreated(View view, Bundle savedInstanceState) { list = (ListView) getActivity().findViewById(android.R.id.list); //also I tried view.findViewById(android.R.id.list) ............ adapter = new LazyAdapter(getActivity(), mSource); list.setAdapter(adapter); } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container,

changing menu item programmatically is not working in android

北城余情 提交于 2019-12-02 12:18:15
问题 I have a menu item and I want to change its visibility programmatically. The menu is this <?xml version="1.0" encoding="utf-8"?> <menu xmlns:android="http://schemas.android.com/apk/res/android" > <item android:id="@+id/pencil" android:orderInCategory="100" android:showAsAction="always" android:visible="true" android:title="@string/for_pencil"/> </menu> then some where in my code I have ((MenuItem) findViewById(R.id. pencil)).setVisible(false); Error: E/AndroidRuntime(13845): FATAL EXCEPTION:

Disabled menu items in Winforms still show subitems

岁酱吖の 提交于 2019-12-02 10:32:58
If I create a menu with two items (say "Item1" and "Item2" and then create two subitems under each one (1A, 1B, 2A and 2B), and then disable Item1, I'd expect that 1A and 1B wouldn't show. And, indeed, if I move onto Item1 they don't. Unless I then move on to Item2, wait for 2A and 2B to show, and then move back to Item1. At which point 1A and 1B both pop up, fully active. Is this a known bug? Is it something I can work around? Any suggestions? The users want to be able to see the things that are currently disabled, or I'd just make things invisible. Sadly, this isn't an option we can easily

Eclipse plugin menu item is not visible

女生的网名这么多〃 提交于 2019-12-02 10:25:35
I tried to add a menu item to package explorer's right click menu. But my menu item is not visible when i run my plugin. what am i missing? here is my plugin.xml: <?xml version="1.0" encoding="UTF-8"?> <?eclipse version="3.4"?> <plugin> <extension point="org.eclipse.ui.menus"> <menuContribution locationURI="popup:org.eclipse.jdt.ui.PackageExplorer"> <command commandId="kodsayici.counter" label="Count" style="push"> <visibleWhen checkEnabled="false"> <with variable="menuSelection"> <iterate ifEmpty="false" operator="or"> <adapt type="org.eclipse.jdt.core.ICompilationUnit"> </adapt> </iterate> <

Why is item.getMenuInfo() null?

余生颓废 提交于 2019-12-02 10:12:50
问题 Within my ListVeiw item I have 4-8 ImageView(some of them are invisible depended of some value) and 4 TextView. When I Long click to item of Listview the (AdapterContextMenuInfo) item.getMenuInfo() returns me null. In my adapter I have defined the following methods: public int getCount() { return NewList.size(); } public Object getItem(int position) { return position; } public long getItemId(int position) { return position; } public void Remove(int id){ notifyDataSetChanged(); } public View

Splash Screen Causes MenuItems not to appear

陌路散爱 提交于 2019-12-02 09:35:14
I've built a splash screen that loads a (splash) activity and then starts another activity and it works fine. (I've attached it below - it's called SPLASH 1) I created another splash screen to replace this one which is supposed to only run once - then after creating a SharedPreferences boolean it is supposed to load another activity. Everything seems fine with this but now when it loads the new activity, none of the menuitems appear. I have no idea what changed in SPLASH 2 - but something in there is causing the MenuItems not to appear after it loads the exact same activity SPLASH 1 does