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
Related
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
I've a menu.xml file, where I've:
<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=".main.MainActivity"
tools:ignore="..">
<item android:id="#+id/test_button"
android:icon="#drawable/search"
android:title="#string/.."
app:showAsAction="always|collapseActionView" />
</menu>
Any item I add here is being shown on the right side.
There's also default "back" button which I can easily hide/disable by mActionBar.setDisplayHomeAsUpEnabled(false);. The position of "back" button is precisely what I want, just "custom" button. This should be only possible when entering specific Fragment, let's say Fragment A.
Activity is extending AppCompatActivity.
How can I do this? What is the best way (cleanest) of doing this? An example would be great!
Yes it is possible you have to create your own custom view for action bar and set it this way
mActionBar.setCustomView(customView);
mActionBar.setDisplayShowCustomEnabled(true);
Hello i want to change 4 to an help icon or if this is not possible, hide it and add a help icon to 3.
I dont want it to be a dropdown menu, i just want a clickable icon.
And is there a way to hide/show it from within a fragment?
I tried to change res/menu/menu_main3.xml but nothing happened.
<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.test.test.Main3Activity">
<item
android:id="#+id/action_help"
android:icon="#drawable/ic_help_outline_black_24dp"
android:orderInCategory="100"
app:showAsAction="always"/>
If you want to do so, you have to implement your custom Toolbar, which is just a ViewGroup. So you will be able to add and adjust any views (in this case it would be ImageButton)
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>