android-menu

android getMenuInflater() in a fragment subclass - cannot resolve method

一笑奈何 提交于 2019-12-03 05:36:48
I am trying to inflate a menu in a class that inherits the Fragment class. Here is my OnCreateOptionsMenu() method - @Override public boolean OnCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.forecastfragment, menu) ; return true; } This raises the following error: Cannot resolve method 'getMenuInflater()' I tried : MenuInflater inflater = getActivity().getMenuInflater(); but then Android Studio highlights @Override in red and states: Method does not override method from its superclass I also tried to create a getMenuInflater method in the same class and have it return new

Android align menu items to left in action bar

陌路散爱 提交于 2019-12-03 05:29:44
i have action bar in my application that displays menu items defined in my res/menu/activity_main.xml My menu items are aligned to right on action bar. I want them to be aligned to left. Only solutions i found for this used custom action bar, like this one: Positioning menu items to the left of the ActionBar in Honeycomb However, i dont want to create custom layout for my menu . I want to use default menu items generated from my res/menu/activity_main.xml . Is this possible? csenga Well, i was curious about this, so i dug deep inside the SDK's source. I used AppCompatActivity with 3 menu item

What is the difference between onCreateOptionsMenu(Menu menu) and onPrepareOptionsMenu(Menu menu)?

最后都变了- 提交于 2019-12-03 05:25:35
问题 Explain difference between onCreateOptionsMenu(Menu menu) and onPrepareOptionsMenu(Menu menu) . 回答1: onCreateOptionsMenu() is called once. onPrepareOptionsMenu() is called every time the menu opens. From the onCreateOptionsMenu() documentation: This is only called once, the first time the options menu is displayed. To update the menu every time it is displayed, see onPrepareOptionsMenu(Menu). 来源: https://stackoverflow.com/questions/14043631/what-is-the-difference-between

How do you remove an inflated menu/items from the new Lollipop Toolbar?

ぐ巨炮叔叔 提交于 2019-12-03 02:03:07
I include a v7 Toolbar in my layout. <android.support.v7.widget.Toolbar android:id="@+id/toolbar" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@android:color/white" /> I'm inflating a menu into it with the following: mToolbar.inflateMenu(R.menu.options_add_contact); Now how do I know remove/reset it? I've tried a couple shots in the dark: inflating an empty menu mToolbar.inflateMenu(0) moolbar.setMenu(null, null) toolbar.setMenu(null, null) I am not entirely sure if this is what you mean nor have tried it but. mToolbar.getMenu().clear(); should

How can I get menu item in NavigationView?

試著忘記壹切 提交于 2019-12-03 01:01:36
<android.support.design.widget.NavigationView android:id="@+id/drawer_nav" android:layout_width="wrap_content" android:layout_height="match_parent" android:layout_gravity="start" android:theme="@style/Theme.AppCompat.Light.NoActionBar" app:headerLayout="@layout/drawer_header" app:menu="@menu/menu_drawer" /> I am using android.support.design.library for material design. What I want is to hide some menu items when the user is not logged-in. Now I have trouble to get the menu item in NavigationView . I have tried: MenuItem logoutItem = (MenuItem) mNavigationView.findViewById(R.id.menu_logout);

Android Studio waiting for build to finish

谁说胖子不能爱 提交于 2019-12-03 00:42:32
问题 I have a problem. When I start a new project in Android Studio and select a navigation drawer activity it happens. I don't have access to my activiy_main_drawer.xml on "Design" and it keeps saying "Waiting for build to finish.". I really don't know what I have to do. I tried to uninstall and reinstall Android Studio, and it didn't help. 回答1: I've just run into the exact same problem. I simply solved it by choosing Sync Project with Gradle Files . This will trigger a Gradle re-import and a

ActionBar capacity/overflow not changing on orientation change

╄→尐↘猪︶ㄣ 提交于 2019-12-03 00:18:54
I have an app using the ActionBar, where I handle orientation changes myself: android:configChanges="keyboard|keyboardHidden|orientation|screenSize" ...and the menu should fit in the ActionBar without overflow in landscape, but not in portrait: <?xml version="1.0" encoding="utf-8"?> <menu xmlns:android="http://schemas.android.com/apk/res/android"> <item android:title="@string/Game" android:id="@+id/game" android:icon="@android:drawable/ic_menu_manage" android:showAsAction="ifRoom|withText"/> <item android:title="@string/Type" android:id="@+id/type" android:icon="@android:drawable/ic_menu_edit"

Different menu for different tabs in tab+swipe application for android project

試著忘記壹切 提交于 2019-12-03 00:09:15
I am a beginner to android applications and java, basically I am a PHP developer. I've a project for a tab+swipe application, Reseller.java package com.idevoc.onsitereseller; import java.util.ArrayList; import android.app.ActionBar; import android.app.ActionBar.Tab; import android.app.Activity; import android.os.Bundle; import android.support.v4.app.Fragment; import android.support.v4.app.FragmentActivity; import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentPagerAdapter; import android.support.v4.app.FragmentTransaction; import android.support.v4.view.ViewPager

Fragments, with the same menu, on the same layout cause duplicated menuitem

此生再无相见时 提交于 2019-12-02 23:33:07
I have a layout which has 2 fragments. These fragments uses the same menu, because I have another layouts that has only one of these (used in small screen device). My problem is menu items of each fragments shows in the menu, and since they're from the same menu, they are duplicated to each others. I need to display only menu from one fragment, not both. Is there anyway I could archive this ? Or, probably better, create 2 different menu. One for the layouts that has one of these fragment alone (which is used in small-screen device), and another one for layout having both fragments. How could I

Light.DarkActionBar menu item text colour unchangeable?

回眸只為那壹抹淺笑 提交于 2019-12-02 19:05:07
The application I've been developing uses ActionBarSherlock, and the main theme inherits from Theme.Sherlock.Light.DarkActionBar. The design requires that the overflow menu popups have a dark coloured background and white text. This works fine for devices without a physical menu button, and the text appears white as intended. However, if the device DOES have a physical menu button, the text shown in the menu displayed remains black. My main theme contains <item name="android:panelBackground">@drawable/menu_hardkey_panel</item> ...Where @drawable/menu_hardkey_panel is a dark coloured 9patch.