Is there a way in which we can display icon along with text in android over flow menu of action bar. My code is below :
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:id="#+id/menu_share"
android:title="share"
android:showAsAction="always"
android:actionProviderClass="android.widget.ShareActionProvider" />
<item
android:id="#+id/action_search"
android:showAsAction="always|collapseActionView"
android:icon="#drawable/ic_menu_search"
android:title="Search"
android:actionViewClass="android.widget.SearchView">
<item
android:id="#+id/item_refresh"
android:icon="#drawable/ic_menu_refresh"
android:title="Refresh"
android:showAsAction="ifRoom|withText"
/>
<item
android:id="#+id/item_save"
android:icon="#drawable/ic_menu_save"
android:title="Save"
android:showAsAction="ifRoom|withText"
></item>
</menu>
Can anyone help me is sorting out this issue. I need to display both icon along with text in overflow that appears on the top right of action bar.
Thanks in advance
As far as I understand, Action Overflow just displays the text (android:title). I've been looking through some apps, and none of them have "icon+text" on items within the Action Overflow.
AFAIK, this is not possible. What you can do is use a ListPopupWindow to accompish this. I had to use a custom bar instead of ActionBar, since it doesn't seem very customizable and I have used PopupMenu but I haven't tried to put icons in yet. But ListPopupWindow should allow you too. You may have to use a custom bar. Possibly attach it to the oveflow button somehow but I'm not sure that is possible
Note that ListPopupWindow needs API >=11
Try creating customized overflow menu:
<item
android:id="#+id/action_overflow"
android:icon="#drawable/overflow"
android:showAsAction="always">
<menu>
<item android:id="#+id/menu_share"
android:title="share"
android:showAsAction="always"
android:actionProviderClass="android.widget.ShareActionProvider" />
<item
android:id="#+id/action_search"
android:showAsAction="always|collapseActionView"
android:icon="#drawable/ic_menu_search"
android:title="Search"
android:actionViewClass="android.widget.SearchView">
<item
android:id="#+id/item_refresh"
android:icon="#drawable/ic_menu_refresh"
android:title="Refresh"
android:showAsAction="ifRoom|withText"
/>
<item
android:id="#+id/item_save"
android:icon="#drawable/ic_menu_save"
android:title="Save"
android:showAsAction="ifRoom|withText"
></item>
</menu>
</item>
you Need to add tools:context="your class" to menu tag
<?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"
xmlns:tools="http://schemas.android.com/tools"
tools:context=".activities.BaseActivity">
<item
android:id="#+id/action_notification1"
android:icon="#drawable/three"
android:title="action_notification"
app:showAsAction="always">
<menu>
<item
android:id="#+id/profile"
android:icon="#drawable/profile"
android:orderInCategory="100"
android:title="PROFILE" />
<item
android:id="#+id/c"
android:icon="#drawable/correct_tick"
android:orderInCategory="100"
android:title="COMPLETED TRIPS" />
<item
android:id="#+id/app"
android:icon="#drawable/report_issue"
android:orderInCategory="100"
android:title="REPORT ISSUES" />
<item
android:id="#+id/r"
android:icon="#drawable/correct_tick"
android:orderInCategory="100"
android:title="REACHED CENTER" />
<item
android:id="#+id/pdf"
android:icon="#drawable/pdf_image"
android:orderInCategory="100"
android:title="BAG INFO" />
<item
android:id="#+id/l"
android:icon="#drawable/logout"
android:orderInCategory="100"
android:title="LOGOUT" />
</menu>
</item>
</menu>
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main, menu);
menu.getItem(0).getSubMenu().getItem(3).setVisible(false);
menu.getItem(0).getSubMenu().getItem(4).setVisible(true);
return super.onCreateOptionsMenu(menu);
}
you shold write tool:context to menu tag then run you will get icons to your text
Related
In my application need to set a custom layout for the actionbar overflow menu as shown in the image, need suggestions how to achieve this.
You can edit your menu.xml according to your need. Below is just an example to show it is done
<item android:id="#+id/menu_save"
android:icon="#drawable/icon_save"
android:title="Save" />
<item android:id="#+id/menu_search"
android:icon="#drawable/icon_search"
android:title="Search" />
<item android:id="#+id/menu_share"
android:icon="#drawable/icon_share"
android:title="Share" />
<item android:id="#+id/menu_delete"
android:icon="#drawable/icon_delete"
android:title="Delete" />
<item android:id="#+id/menu_preferences"
android:icon="#drawable/icon_preferences"
android:title="Preferences" />
Edit the following code in your menu.xml file
<item
android:id="#+id/help"
android:title="Help"
app:showAsAction="never"
android:orderInCategory="100"/>
<item
android:id="#+id/Chng_pswd"
android:title="Change Password"
app:showAsAction="never"
android:orderInCategory="200"/>
<item
android:id="#+id/logout"
android:title="LogOut"
app:showAsAction="never"
android:orderInCategory="300"/>
Add this in your menu.xml items you want to display in your actionBar overflow menu:
app:showAsAction="never"
#Emzor
How to set custom layout for the menu , I have given app:showAsAction="never" for the menu items , It is displayed as in
How to set custom layout for the menu ? I have to show options as in the Image which is present in my question.
I want to hide all icons in action bar when user touches the search icon. But one icon is not hiding.
My xml:
<?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/action_search"
android:icon="#drawable/ic_search_white_36dp"
android:title="Ara"
app:showAsAction="always"
android:iconifiedByDefault="true"
app:actionViewClass="android.widget.SearchView"/>
<item android:id="#+id/action_shuffle"
android:icon="#drawable/ic_autorenew_white_24dp"
android:title="Karıştır"
app:showAsAction="always" />
<item android:id="#+id/action_premium"
android:icon="#drawable/ic_star_white_24dp"
android:title="Premium"
app:showAsAction="always" />
<item android:id="#+id/action_favorites"
android:icon="#drawable/ic_people_white_24dp"
android:title="Takip Listesi"
app:showAsAction="always" />
<item android:id="#+id/action_settings"
android:icon="#drawable/ic_settings_white_24dp"
android:title="Settings"
app:showAsAction="always" />
<item android:id="#+id/action_fullpicture"
android:icon="#drawable/ic_action_picture"
app:showAsAction="always"
android:visible="false" />
</menu>
Before:
After:
How can I hide action_shuffle too? Other icons automaticly hiding I didn't do anything special.
You should change the app:showAsAction = "always" to app:showAsAction = "ifRoom".
Other way could be this answer, take a look.
Please help me. I use the context menu in Action Bar (CAB). Listing menu has the following code
<?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/add_cxtmenu"
android:icon="#android:drawable/ic_menu_add"
android:showAsAction="always"
android:orderInCategory="1"
android:title="edit"/>
<item/>
<item
android:id="#+id/edit_cxtmenu"
android:icon="#android:drawable/ic_menu_edit"
android:showAsAction="always"
android:orderInCategory="2"
android:title="edit"/>
<item
android:id="#+id/delete_cxtmenu"
android:icon="#android:drawable/ic_menu_delete"
android:showAsAction="always"
android:orderInCategory="3"
android:title="delete"/>
</menu>
So the menu should consist of three items. Each item has a parameter android:showAsAction="always"
In the end, I had to get three icons on the panel ActionBar. But in reality, I have two icons together into a button overflowbutton. How to fix it? I can not find the answer to this problem.
Theme my app
<style name="AppTheme" parent="#style/Theme.AppCompat.Light">
Try this.
<?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/add_cxtmenu"
android:icon="#android:drawable/ic_menu_add"
app:showAsAction="always"
android:orderInCategory="1"
android:title="edit"/>
<item/>
<item
android:id="#+id/edit_cxtmenu"
android:icon="#android:drawable/ic_menu_edit"
app:showAsAction="always"
android:orderInCategory="2"
android:title="edit"/>
<item
android:id="#+id/delete_cxtmenu"
android:icon="#android:drawable/ic_menu_delete"
app:showAsAction="always"
android:orderInCategory="3"
android:title="delete"/>
</menu>
Try to change this:
android:showAsAction="always"
For this:
app:showAsAction="always"
Also you couldn´t have enought room. Try to remove your title or do it small.
I have the following items to display on the ActionBar. They are :- Share and Settings.
Under Settings I need to show a drop down menu with two more options.
Here is my code:-
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<!-- Search, should appear as action button -->
<item android:id="#+id/action_share"
android:icon="#drawable/share"
android:title="Share"
android:showAsAction="ifRoom" />
<!-- Settings, should always be in the overflow -->
<item android:id="#+id/action_settings"
android:title="Settings"
android:showAsAction="never" />
</menu>
How can I go ahead wit it?
Try this code for subMenu using XML
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="#+id/action_share"
android:icon="#drawable/share"
android:title="Share"
android:showAsAction="ifRoom" />
<item android:id="#+id/action_settings"
android:icon="#drawable/setting"
android:title="#string/settings"
android:showAsAction="ifRoom|withText">
<menu>
<item android:id="#+id/option1"
android:icon="#drawable/yourIcon"
android:title="SubMenu1" />
<item android:id="#+id/option2"
android:icon="#drawable/yourIcon"
android:title="SubMenu2" />
</menu>
</item>
</menu>
JAVA code for Activity
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.actionbar, menu);
return true;
}
Despite there are some icons associated with certain action and have no enough space in the Actionbar, they appear in the optionsMenu instead of appearing in the overflow icon.
I am inflating the actionBar with five icons each one has a specific functionality "Please refer to the XML file below", the items which have the android:showAsAction=never
I expect them to implicitly reside inside the overflow icon on the actionBar, but when I run the App, any item with the property android:showAsAction=never instead it appears in the optionsMenu. Why that happens? and I hope i explained the problem clearly.
Update:
Simply, I want, if there is no space for the icon to be placed on the ActionBar, They should be placed inside the overflow icon as shown in the image " the icon with three vertical dots over each other".
To Note:
I am using Galaxy Note3
Why my question is marked as a duplicate. The question suggested as a duplicate is different than mine? Please review the question again.
Java_Code:
public class ActionBarActivityTest00 extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_action_bar_activity_test00);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.action_bar_activity_test00, menu);
return super.onCreateOptionsMenu(menu);
}
XML:
<menu
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:context="com.example.actionbaractivitytest.ActionBarActivityTest00" >
<!-- Search / will display always -->
<item android:id="#+id/action_search"
android:icon="#drawable/ic_action_search"
android:title="action_search"
android:showAsAction="ifRoom"/>
<!-- Location Found -->
<item android:id="#+id/action_location_found"
android:icon="#drawable/ic_action_location_found"
android:title="action_location_found"
android:showAsAction="ifRoom" />
<!-- Refresh -->
<item android:id="#+id/action_refresh"
android:icon="#drawable/ic_action_refresh"
android:title="action_refresh"
android:showAsAction="ifRoom" />
<!-- Help -->
<item android:id="#+id/action_help"
android:icon="#drawable/ic_launcher"
android:title="action_help"
android:showAsAction="never"/>
<!-- Check updates -->
<item android:id="#+id/action_check_updates"
android:icon="#drawable/ic_action_refresh"
android:title="action_check_updates"
android:showAsAction="never" />
Add below property in showasaction=never All menu items
android:orderInCategory="2"
thats it..it will shown in overflow men..
Changes My Sample Code for your scenario and it works fine in my app
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:context="com.example.demo.MainActivity" >
<item
android:id="#+id/action_settings1"
android:orderInCategory="100"
android:title="#string/action_settings"
app:showAsAction="ifRoom"/>
<item
android:id="#+id/action_settings2"
android:orderInCategory="100"
android:title="#string/action_settings"
app:showAsAction="ifRoom"/>
<item
android:id="#+id/action_settings3"
android:orderInCategory="100"
android:title="#string/action_settings"
app:showAsAction="ifRoom"/>
<item
android:id="#+id/action_settings"
android:orderInCategory="100"
android:title="#string/action_settings"
app:showAsAction="never"/>
<item
android:id="#+id/action_settings5"
android:orderInCategory="100"
android:title="#string/action_settings"
app:showAsAction="never"/>
Try this:
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:context="com.example.fafad.MainActivity" >
<!-- Search / will display always -->
<item android:id="#+id/action_search"
android:icon="#drawable/ic_action_search"
android:title="action_search"
android:orderInCategory="1"
app:showAsAction="ifRoom"/>
<!-- Location Found -->
<item android:id="#+id/action_location_found"
android:orderInCategory="2"
android:icon="#drawable/ic_action_location_found"
android:title="action_location_found"
app:showAsAction="ifRoom" />
<!-- Refresh -->
<item android:id="#+id/action_refresh"
android:icon="#drawable/ic_action_refresh"
android:orderInCategory="3"
android:title="action_refresh"
app:showAsAction="ifRoom" />
<!-- Help -->
<item android:id="#+id/action_help"
android:icon="#drawable/ic_launcher"
android:orderInCategory="4"
android:title="action_help"
android:showAsAction="never"/>
<!-- Check updates -->
<item android:id="#+id/action_check_updates"
android:icon="#drawable/ic_action_refresh"
android:orderInCategory="5"
android:title="action_check_updates"
app:showAsAction="never" />
</menu>