Menu Items are not showing on Action Bar
Since you set the showAsAction
attribute to never
, then these menu items will never show as action views. Try this:
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="@+id/action_settings"
android:orderInCategory="100"
android:showAsAction="ifRoom|withText"
android:title="@string/action_option1"/>
<item
android:id="@+id/action_settings34"
android:orderInCategory="100"
android:showAsAction="ifRoom|withText"
android:title="@string/action_option2"/>
<item
android:id="@+id/action_settings3"
android:orderInCategory="100"
android:showAsAction="ifRoom|withText"
android:title="@string/action_option3"/>
</menu>
Menu is not showing on Action Bar
there is a problem in enclosing of menu items:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item android:id="@+id/exit"
android:orderInCategory="102"
android:showAsAction="ifRoom|withText"
android:icon="@drawable/ic_menu_exit"
android:title="@string/menuitem_exit" /> //item not enclosed properly
<item android:id="@+id/about"
android:orderInCategory="101"
android:showAsAction="ifRoom|withText"
android:icon="@drawable/ic_menu_info_details"
android:title="@string/menuitem_about" />
</menu>
Keep it simple:
@Override
public boolean onPrepareOptionsMenu(final Menu menu) {
getMenuInflater().inflate(R.menu.optionsmenu, menu);
return super.onCreateOptionsMenu(menu);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.optionsmenu, menu);
return true;
}
android - menu item not showing in action bar
You should use below method after initialization of Toolbar.
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
Action Bar Not Showing Menu Items
You are missing following function in your Fragment
that indicates this Fragment
has a menu.
setHasOptionsMenu(true);
Call this function in your onCreateView
function.
http://developer.android.com/reference/android/app/Fragment.html#setHasOptionsMenu(boolean)
action bar menu item are showing but not working
i have manage to find the problem and i solved it. the problem was with Drawer layout which was in the content.xml file i take this drawer and place it in Activity.xml and problem solved....
<android.support.v4.widget.DrawerLayout
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
<include layout="@layout/content_main" />
</FrameLayout>
ActionBar menuItem not showing text
I'm not sure why withText wouldn't work for me so I just created an actionLayout
to use instead.
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/toolbar_right_button"
android:icon="@drawable/ic_toolbar_locked"
android:orderInCategory="1"
android:title="Logout"
app:actionLayout="@layout/menu_item_logout"
app:showAsAction="ifRoom|withText"/>
</menu>
and the actionLayout
:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<Button
android:id="@+id/logout_button"
style="?android:attr/borderlessButtonStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableRight="@drawable/ic_toolbar_locked"
android:gravity="center_vertical"
android:text="Logout"
android:textColor="@color/PrimaryColour"/>
</RelativeLayout>
ActionBar Action Items not showing
This is because if you use the support AppCompat ActionBar library and ActionBarActivity you should create your menus in a different than the standard way of creating XML menus in ActioBarSherlock or the default ActionBar.
So try this code:
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item android:id="@+id/action_search"
android:icon="@drawable/ic_action_search"
android:title="@string/action_search"
app:showAsAction="always" />
<item android:id="@+id/action_compose"
android:icon="@drawable/ic_action_compose"
android:title="@string/action_compose"
app:showAsAction="always"/>
</menu>
and report if this works.
Note: check the extra prefix xmlns:app
which should be used instead!
Related Topics
How to Start an Android Application from the Command Line
Official "Boost Library" Support for Android and iOS
How to Change Viewpager's Page
Android Fragment Onrestoreinstancestate
Android: How Does Gridview Auto_Fit Find the Number of Columns
Android Webview with Client Certificate
How to Include Data Files with the App's APK
Android Expandablelistview and SQLite Database
Android Retrofit - Onprogressupdate for Showing Progress Notification
How Do We Distinguish Never-Asked from Stop-Asking in Android M's Runtime Permissions
How to Encrypt/Decrypt String in Android
Android: Integer from Xml Resource
Using Notifyitemremoved or Notifydatasetchanged with Recyclerview in Android
How to Open Private Files Saved to the Internal Storage Using Intent.Action_View
How to Write Jarlist Cache File While Creating Android Project