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.
Related
<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=".MainActivity">
<item
android:id="#+id/action_settings"
android:title="Settings"
android:orderInCategory="100"
app:showAsAction="never" />
<item android:id="#+id/action_search"
android:orderInCategory="200"
android:title="Search"
android:icon="#android:drawable/ic_search_category_default"
app:showAsAction="ifRoom" />
<item android:id="#+id/action_user"
android:orderInCategory="300"
android:title="User"
android:icon="#android:drawable/ic_dialog_info"
app:showAsAction="ifRoom" />
</menu>
I'm experimenting with android action bar and I'm confused how the settings and other actions are added to my action bar from the menu.
How did android determine that the first item in my list is to be added the three dot menu?
Because you asked android to not show it as action, like this:
app:showAsAction="never"
while for other items you show them when there is enough space to show:
app:showAsAction="ifRoom"
I want a menu item in my toolbar when clicked to act like a SearchView. I tried this, but the icon was still the default SearchView icon...
<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=".MainActivity">
<item
android:id="#+id/action_edit_courses"
android:title="#string/action_edit"
android:orderInCategory="100"
android:icon="#android:drawable/ic_menu_edit"
app:actionViewClass="android.widget.SearchView"
app:showAsAction="always" />
<item
android:id="#+id/action_delete_courses"
android:title="#string/action_delete"
android:orderInCategory="100"
android:icon="#android:drawable/ic_menu_delete"
app:actionViewClass="android.widget.SearchView"
app:showAsAction="ifRoom" />
Please I don't know how to get through with it... Thank you in advance
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've got this problem but the thing is that I do have a title
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:android="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/tools">
<!-- Search, should appear as action button -->
<item
android:title="#string/action_search"
android:id="#+id/action_search"
android:icon="#drawable/ic_action_search"
android:showAsAction="ifRoom" />
<item
android:title="#string/action_settings"
android:id="#+id/action_settings"
android:showAsAction="never" />
</menu>
in the strings xml file i did the strings, the program even switches the action_search and action_settings with its string - search and settings.
Just a wrong XML namespace! Try with:
<menu xmlns:android="http://schemas.android.com/apk/res/android">
</menu>
And as G.T. suggested you should consider using appcompat on the showAsAction property (only needed if you want to support API < 11):
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="#+id/item1"
android:icon="#drawable/ic_launcher"
app:showAsAction="ifRoom|withText"
android:title="#string/Add_New" />
</menu>
Note:
The appcompat library is compatible with some old Android versions (API 7+) that can't handle the showAsAction property because they don't have the ActionBar (API < 11).
can you remove those things xmlns:android="schemas.android.com/apk/res-auto"; xmlns:android="schemas.android.com/tools";
Also try to follow Goolge dev examples here http://developer.android.com/guide/topics/ui/menus.html
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="#+id/new_game"
android:icon="#drawable/ic_new_game"
android:title="#string/new_game"
android:showAsAction="ifRoom"/>
<item android:id="#+id/help"
android:icon="#drawable/ic_help"
android:title="#string/help" />
</menu>
It actually need a namespace to identify the process.
<?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_shuffle"
android:icon="#drawable/android_music_player_rand"
android:orderInCategory="1"
app:showAsAction="always"
android:title="Shuffle"
android:onClick="shuffle"/>
<item
android:id="#+id/action_end"
android:icon="#drawable/end"
android:orderInCategory="2"
app:showAsAction="always"
android:title="End"
android:onClick="end"/>
</menu>
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