I have a problem, in my app I need to add 2 buttons to the ActionBar, i change the menĂ¹ file in this way
<menu
xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="#+id/navigation_drawer"
android:icon="#drawable/ic_drawer"
android:title="Drawer"
android:showAsAction="ifRoom" />
<item android:id="#+id/info"
android:icon="#drawable/ic_info_outline_white_24dp"
android:title="info"
android:showAsAction="ifRoom" />
</menu>
but my items are in the overflow button without the image , only the text , how can I do to take off from there and make images appear on ActionBar ? it would be possible to put one on the left and one to the right of the name of the app ?
You can use android:showAsAction="always" to make them always show on the ActionBar.
Related
I have an Xamarin android menu ui code as follows
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<group
android:checkableBehavior="single">
<item
android:id="#+id/sync_now"
android:checked="false"
android:icon="#drawable/ic_logo"
android:title="Sync Now"/>
</group>
</menu>
I am trying to get a split view on this hazard icon along with the transactions count displayed on the right side of the menu group items shown in the image below but am having no luck.
can someone please tell me how i can do this?
I achieved the above ui by creating a different layout file for everything after sync and added it to the item tag as:
<item
android:id="#+id/sync_now"
android:checked="false"
android:icon="#drawable/ic_syncNow"
android:title="Sync Now"
app:actionLayout="#layout/syncNowCounter"/>
make sure you use app:actionLayout instead of android:actionLayout or it will not work.
Im using the ActionBarActivity on my activity and inflating the following menu
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:microecs="http://schemas.android.com/apk/res-auto">
<item android:id="#+id/menu_refresh"
android:icon="#drawable/ic_action_refresh"
android:title="#string/description_refresh"
android:orderInCategory="1"
microecs:showAsAction="ifRoom" />
<!--TODO: get a good logout icon-->
<item
android:id="#+id/menu_logoff"
android:icon="#drawable/ic_action_logout"
android:title="#string/description_logoff"
android:orderInCategory="2"
microecs:showAsAction="never" />
</menu>
The second menu item drawable that i want to appear as a menu and not in the action bar doesn't not appear in my S4 (running 4.3) and also on lower devices running 2.3.7
Just update your code with following code.
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:microecs="http://schemas.android.com/apk/res-auto">
<item android:id="#+id/menu_refresh"
android:icon="#drawable/ic_action_refresh"
android:title="#string/description_refresh"
android:orderInCategory="1"
microecs:showAsAction="ifRoom" />
<!--TODO: get a good logout icon-->
<item
android:id="#+id/menu_logoff"
android:icon="#drawable/ic_action_logout"
android:title="#string/description_logoff"
android:orderInCategory="2"
microecs:showAsAction="ifRoom" />
</menu>
Whenever you are using never then it dont place that item in the Action Bar.
For about menu refer this link.
This is not possible by design. Overflow menus from the action bar don't show icons - that's just a design decision Google made.
You can check more, e.g. here: Displaying icon for menu items of Action Bar in Honeycomb android 3.0
I have this menu layout
<item
android:id="#+id/refresh"
android:icon="#drawable/refresh"
android:title="#string/refresh"/>
<item
android:icon="#drawable/sort_neutral"
android:title="Sort By Date">
<menu>
<item
android:id="#+id/sortNewToOld"
android:icon="#drawable/sort_up"
android:title="Newest To Oldest"/>
<item
android:id="#+id/sortOldToNew"
android:icon="#drawable/sort_down"
android:title="Oldest To Newest"/>
</menu>
</item>
the items "#+id/refresh" and "#drawable/sort_neutral" are shown correctly, but the two icons inside the "android:title="Sort By Date" are not shown, I just can see the title of them. any help would be appreciated.
note
I am using real mobile song ericsson 2.3.1
Your icon are probably too large for the menu. Make sure you are using a correct icon size.
I am working with the Android 3.0.
I have in the action bar 3 items and one of them is the menu of the application, it also has sub-menu in it.
I want to change the order of the icons so the menu won't be in the right place, I want it to be between the two other items. I tried to change the order in the xml with no success.
Does anyone has an idea how to set the order?
Try setting android:menuCategory and android:orderInCategory for your menu items to set the ordering.
Example:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="#+id/launch_search"
android:icon="#android:drawable/ic_menu_search"
android:title="#string/search_programs"
android:menuCategory="container"
android:orderInCategory="2"
android:showAsAction="always" />
<item android:id="#+id/preferences_screen"
android:icon="#android:drawable/ic_menu_preferences"
android:title="#string/preferences" />
<item android:id="#+id/refresh"
android:icon="#drawable/ic_menu_refresh"
android:menuCategory="container"
android:orderInCategory="1"
android:title="#string/refresh_items"
android:showAsAction="ifRoom" />
</menu>
It will have the same effect as declaring launch_search -action as last, but this way you'll have your actions in the right order for 2.x and older devices while being able to control action ordering for 3.x -devices.
The menu will always go to the right, you cannot control its placement.
Here is my XML
<?xml version="1.0" encoding="UTF-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="#+id/refresh" android:title="Home"
android:icon="#drawable/menu_home" />
<item android:id="#+id/search" android:title="Search"
android:icon="#drawable/menu_search" />
<item android:id="#+id/help" android:title="Help" android:icon="#drawable/menu_help" />
</menu>
Icon is getting displayed but title doesn't. Please advise.
I'll post this as an answer then...
The size of menu pixes can be too large (such as 72x72). Make sure you use the proper size icons for your current display.
I had the same problem, but my menu icon size was 32x32. And still displayed over the text. So, I played a little with the sizes, and set it to about 47x47 and it finally worked.
So, if this happens, try to play with the image sizes.