I want to know if there a solution to add an image next to a text in the option menu in xml like the photo:
by adding icon attribute to your menu item xml and setting show as action to never like that :
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="#+id/favorite"
android:icon="#drawable/ic_favorite_24dp"
android:title="#string/favorite"
android:contentDescription="#string/content_description_favorite"
app:showAsAction="never" />
</menu>
where the ic_favorite_24dp could be any image/vector asset icon drawable you like in your drawables folder.
check this link and this link for more information
Related
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>
I've set up a simple menu with one position like this:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" tools:context=".MainActivity">
<item android:id="#+id/action_language" android:title="#string/language"
android:orderInCategory="100" />
</menu>
using
Theme.AppCompat.Light.DarkActionBar
style. When I click the three dots the menu position appears instead of the icon, not below it? Is there any way to make it appear under the icon, not 'on' it?
Actually you can't do anything with this icon, but you can create menu item with android:actionLayout="#layout/custom_lauout". Then you can create Popup Window, which allows such positioning. In popupWindow you will show all items that must show under "three dots item".
Here rea a few links which can help you: http://developer.android.com/reference/android/widget/PopupWindow.html
https://stackoverflow.com/a/23516493/3864698
I have created a sample android application that just displays some text and i can see that the menu bar at the top of the activity contains name of the application but not the icon of the application. The menu is also very thin just containing application name with a small font. Going through various tutorial i found that we have to select a particular menu style while creating the application to have a menu that contains both application name and icon, but my application just contains application name and the menu is very thin. Is it possible to increase the menu height now and add application icon to it dynamically or by making some changes in menu xml file?
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="#+id/app_name" android:icon="#drawable/ic_launcher"
android:title="My App" />
</menu>
If you want to customize the ActionBar, here you are a complete tutorial for it:
How can I implement custom Action Bar with custom buttons in Android?
It's very good an complete for customizing almost everything, so I recommend it to you.
Even tough, I ask you to change your question in order to make more clear the target of it, now you know what you were triying to mean ;)
<menu xmlns:tools="schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android"
tools:context="com.example.sample.getMsgActivity"
xmlns:yourapp="http://schemas.android.com/apk/res-auto">
<!-- Search, should appear as action button -->
<item android:id="#+id/action_write"
android:icon="#drawable/ic_action_refresh"
android:title="#string/action_write"
yourapp:showAsAction="ifRoom" />
<!-- Settings, should always be in the overflow -->
<item android:id="#+id/action_read"
android:title="#string/action_read"
yourapp:showAsAction="never" />
REMEMBER: clean, then build. it should work then.
I use the Sherlock actionbar library. I want to create a actionbar like this:
Two menu items on the right, and only one can be selected at one time (like a radio group).
My problem is, how can I keep selected state of menu item? Or can I set the menu item background programmatically?
I programmatically changed the menu item icon, like this:
Could anyone help me?
Edit
I'm using menuItem.setIcon(R.drawable.actionbar_icon1) to set the menu item icon.
And the drawable/actionbar_icon1.xml is defined as below:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:drawable="#drawable/actionbar_selected_bg" />
<item android:drawable="#drawable/actionbar_icon1_img"></item>
</layer-list>
and #drawable/actionbar_selected_bg is defined like this:
<drawable name="actionbar_selected_bg">#0277ca</drawable>
#drawable/actionbar_icon1_img is an image.
This does not work, as the second picture shows.
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>