Please take in consideration that I'm refering to the Toolbar Widget(Android L/API 21+)
By overflow menu and icons I mean something like this one :
Something more difficult : Is there any way that the icons appear on the RIGHT side of the text?
create a menu in menu, for example: main_activity_actions.xml
and use this code for the toolbar, try it:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:All4One="http://schemas.android.com/apk/res-auto">
<item android:id="#+id/algo"//some id
android:icon="#drawable/kami_nomi_zu_shiru_sekai3" //add the image
android:title="nose"
All4One:showAsAction="always">
<menu>
<item android:id="#+id/WIFI"//option to display on the menu
android:icon="#drawable/nisekoi1"//this is a option of the submenu
android:title="#string/WIFI"/>
<item android:id="#+id/DATOS"
android:icon="#drawable/nisekoi6" //this one also is a option
android:title="#string/DATOS"/>
<item android:id="#+id/BT"
android:icon="#drawable/sao1"
android:title="#string/BT"/>
<item android:id="#+id/NADA"
android:icon="#drawable/nisekoi6" //the same
android:title="#string/NADA"/>
</menu>
</item>
</menu>
Related
I'm using AndroidX Navigation architecture and want to know is it possible to replace the ActionBar menu completely or not?
In the project, in the Menu directory, there is a home.xml file that contains a 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"
android:id="#+id/homeMainMenu">
<item
android:id="#+id/action_inbox"
android:icon="#drawable/ic_baseline_mail_outline_24"
android:title="#string/action_inbox"
app:showAsAction="ifRoom" />
<item android:icon="#drawable/ic_baseline_more_vert_24"
android:title="#string/app_name"
app:showAsAction="always">
<menu>
<item
android:id="#+id/action_exitapp"
android:icon="#drawable/ic_baseline_exit_to_app_24"
android:title="#string/action_exit"
app:showAsAction="never" />
</menu>
</item>
</menu>
I want to create another menu XML file like mymenu.xml and on the fragment replace it with the home menu. Because of some reason don't want to replace items.
Is it possible? If "Yes" how to handle item click?
If i got your question correct then i guess you want to create different menu for activity and its fragment. You can do that. Please check here
Remember you've to add hasOptionsMenu in fragment onCreate
it seems that what ever i did i cant set the icons visible to the tool bar, i've tried to do researches on many platforms, but nothing helped.
here is the xml menu:
<?xml version="1.0" encoding="utf-8" ?>
<menu
xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="#+id/event_ic"
android:icon="#mipmap/ic_event"
android:title="profile"
android:showAsAction="always"
/>
<item
android:id="#+id/details_menu"
android:title="details"
android:showAsAction="never"/>
</menu>
you can see that even if i set the android:showAsAction to always, i still get the event item in the pop up menu without the icon.
I have tried every option of the android:showAsAction, and it didn't work!
I think that maybe I can't get the concept of how to do it.
my app
how I want it
Try something like this.
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="#+id/action_cart"
android:icon="#drawable/ic_action_cart"
android:title="Refresh"/>
<item
Your items
</item>
</menu>
http://www.vogella.com/tutorials/AndroidActionBar/article.html
I have an app (for 4.0 and above) which has couple of MenuItems in the ActionBar (one with 'always' and the rest with 'ifRoom' or 'never' property).
So the issue goes like this...
If I launch the app in landscape mode, the ActionBar looks like the following:
When I rotate to landscape from portrait, the ActionBar looks like this:
As you can see, more icons appear than they should be, i.e no space is left for title bar and the tabs menu (Navigation Menu). Actually, the 4 items are shown in the portrait mode (it's a split ActionBar) and it seems that the Android doesn't realise that there's no SplitActionBar there anymore.
Please suggest what I can do to fix this? :)
Edit
My menu.xml:
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="#+id/action_share"
android:icon="#drawable/ic_menu_share"
android:showAsAction="always"
android:title="#string/share"/>
<item
android:id="#+id/action_viewToggle"
android:icon="#drawable/ic_menu_view_as_grid"
android:showAsAction="ifRoom"
android:title="#string/switch_view"/>
<item
android:id="#+id/action_upload"
android:icon="#drawable/ic_menu_upload"
android:showAsAction="ifRoom"
android:title="#string/upload"/>
<item
android:id="#+id/action_newFolder"
android:icon="#drawable/ic_menu_new_folder"
android:showAsAction="ifRoom"
android:title="#string/create_folder"/>
<item
android:id="#+id/action_multiselect"
android:icon="#drawable/ic_menu_select_all"
android:showAsAction="ifRoom"
android:title="#string/selection_mode"/>
<item
android:id="#+id/action_refresh"
android:icon="#drawable/ic_menu_refresh"
android:showAsAction="ifRoom"
android:title="#string/refresh"/>
<item
android:id="#+id/action_settings"
android:icon="#drawable/ic_menu_settings"
android:showAsAction="never"
android:title="#string/action_settings"/>
</menu>
Make sure you take care of each menu item visibility in your menu.xml file, check out the xml ShowAsAction attribute.
here's an example:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="#+id/SOME_MENU_ITEM"
android:icon="#drawable/SOME_ICON"
android:showAsAction="ifRoom" | "never" | "withText" | "always" | "collapseActionView"
android:title="SOME_TITLE"/>
.
.
One of the important attribute xml for menu items is,
android:showAsAction ,that defines the visibility of the action item.
From your code it is evident that if there is room in action bar it'll display it.
So if you don't want it to appear specify android:showAsAction value as never so that whatever the orientation is it'll appear only in the overflow menu.
I actually have two questions:
Is there a way to mark a menu item in the ActionBar as the OK/submission button, or is it just a regular item?
Is there a built-in theme for an OK button in the ActionBar (maybe something that looks like a tick-mark?) or must I create my own image file?
I found this icon in Sherlock, it looks like a tick mark and it seems to do the job:
abs__ic_cab_done_holo_light.png
So this is my menu xml (located in res/menu):
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="#+id/done_item"
android:icon="#drawable/abs__ic_cab_done_holo_light"
android:showAsAction="always"
android:orderInCategory="1"
android:title="#string/done">
</item>
</menu>