is it possible to add a button label like this as a toolbar action menu item?
I tried the following code below
<item
android:id="#+id/action_submit"
android:title="#string/submit_titlecase"
android:visible="false"
android:icon="#drawable/primary_btn"
app:showAsAction="always|withText" />
And it appears blank?
If i remove the android:icon, it appears the text but not the button sourrounding outline
Define a menu item in the following manner:
<item android:id="#+id/action_submit"
android:title="Submit"
app:showAsAction="always"/>
(Basically, if you show as action and you don't provide an icon, the title is shown as a button on the toolbar.)
But if you want it specifically to look like a button like you've put up in your question, make a drawable/mipmap file looking exactly like that and then add android:icon="#drawable/icon" (or #mipmap/icon) into your menu item code.
Related
The buttons on the action bar on this tablet, if shown with text, suffer from text warping as in the screenshot below:
I tried many possible settings combinations (ifRoom, always, withText,...). Even attempting to manipulate the actual view of the button get me nowhere (or maybe I didn't persevere enough). Setting the widths of the TextView and the parent LinearLayout had no effect unless they're fixed numbers.
Any ideas?
EDIT:
I neglected to mention that attempting to use an icon along with text only shows the icon. This is using the native action bar. Below is the xml of the action button above:
<item
android:id="#+id/itemConfig"
android:showAsAction="ifRoom|withText"
android:title="Network Config"
android:visible="true"/>
Setting the menu item in the following manner:
<item
android:id="#+id/itemConfig"
android:icon="#drawable/ic_action_networkconfig"
android:showAsAction="ifRoom|withText"
android:title="#string/network_config"
android:visible="true"/>
causes this
So in essence, the tablet doesn't like text in its action bar. Any clues?
It looks like your menu code is correct. For reference check my menu item 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/itemConfig"
android:icon="#drawable/icon"
app:showAsAction="withText|always"
android:title="#string/network_config"/>
</menu>
Device will show text with icon only if we have space. You can check with landscape mode. Here is the example
Source:
http://developer.android.com/guide/topics/ui/actionbar.html#ActionItems
If your menu item supplies both a title and an icon—with the title and icon attributes—then the action item shows only the icon by default.
If you want to display the text title, add "withText" to the showAsAction attribute.
Note: The "withText" value is a hint to the action bar that the text title should appear. The action bar will show the title when possible, but might not if an icon is available and the action bar is constrained for space.
Long story short, it couldn't be done :)
Sorry if this question sounds stupid, but I am new to android and need help. I have two menu items
<item android:id="#+id/submenu11" android:title="Newest" android:icon="#android:drawable/radiobutton_off_background" />
<item android:id="#+id/submenu12" android:title="Oldest" android:icon="#android:drawable/radiobutton_off_background"/>
They use the radio button icon, but when I launch the app its just a grey circle- unlike what it is supposed to look like. How do I add a theme, or color these icons so that they are not just grey circles and look more like radio buttons? Thanks in advance, would really help
Of question, you just used a radio_off icon, if you want to set an radio button as menu, you should create a custom button on it,like this:
<item
android:id="#+id/action_navigate_search"
android:icon="#drawable/ic_search_white"
android:orderInCategory="1"
android:title="#string/search"
app:actionViewClass="android.support.v7.widget.SearchView"
app:showAsAction="ifRoom|collapseActionView"/>
You can use "actionViewClass" to set a custom view, of you want, there can write android.widget.RadioButton
I have an application without an appbar. Now I want to put 3 Buttons into a menu. I have seen the option to create a toolbar and then add the items programmaticlly. But first I would prefer not to have a bar but just the menu.
I know that that isn´t really important because I can make the bar transparent.
And Second I really don´t want to add the items programmatically. (But defigned in xml.) Is this possible, are there better ways and how can I do it?
If "By the menu" you mean, the overflow menu that exists in the app bar then you can not just the add the menu that way. The app bar or toolbar has to be there to contain that overflow menu. But for giving that sort of effect as you also mentioned you can have the toolbar transparent or you can look into the PopUpMenu, http://developer.android.com/guide/topics/ui/menus.html,
this way you can hide your app bar and can give a separate button which will call PopUpMenu, its going to give you same overflow menu effect.
Regarding your 2nd requirement of putting menu in xml, if i am getting it correct you can have your menu defined like this,
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="#+id/phone"
android:title="#string/phone"
android:icon="#drawable/phone"
android:showAsAction="ifRoom|withText"
/>
<item
android:id="#+id/computer"
android:title="#string/computer"
android:icon="#drawable/computer"
android:showAsAction="ifRoom|withText"
/>
</menu>
You need your CSS anymets revised.
Please consider this codings:
style {template.css}
I think you'll find those are the exact answer.
I am using an menu in action bar with a SearchView in it , the xml defined as:
<item
android:id="#+id/search"
android:orderInCategory="1"
android:showAsAction="ifRoom"
android:icon="#drawable/search"
android:onClick="search"
android:actionViewClass="android.widget.SearchView"
android:title="search"
/>
but from the attached image(the first menu and the 3rd menu has the same image), the search image which should has the white color as the left icon has another background color similiar to light gray. Could any one tell me how to solve this?
I'm not sure what the solution is, but I can tell you why it is happening. The SearchView uses its own icon to display on the action bar. So, when you set the icon in the XML it gets overriden by the default SearchView icon. I'd be interested in anyone's answer to this because this is a problem I actually ran into myself without being able to find an answer.
I have a lot of problems with the development of an action bar. Here are my needs:
I want to add a dropdown in my action bar, which is using custom view because of some custom comportment (animation for example).
The dropdown have to be accessible from an image button (not a spinner which show a text area of the selected element).
The image button that allow to show the dropdown have to be at the left of the action bar.
The dropdown that appear have to contain checkable items, and, when the user check an item, the dropdown have to not be hidden (this allow the user to check multiple items at once).
My application have to work from android 2.3 (I'm using action bar sherlock for that, I specify this because of I can't use PopupMenu on android 2.3).
I have successfully added a dropdown in my action bar by combining my custom view (actionBar.setCustomView(...)) with a menu (menuInflater.inflate(...)). I think the code of my customview is not very important, here is the code of my menu :
<item
android:title="test"
android:drawable="#drawable/dropdown_icon"
android:showAsAction="always">
<menu>
<item
android:id="#+id/item1"
android:title="item 1"
android:checkable="true"/>
<item
android:id="#+id/item2"
android:title="item 2"
android:checkable="true"/>
<item
android:id="#+id/item3"
android:title="item 3"
android:checkable="true"/>
</menu>
</item>
With this solution, I have the following problems :
I'm not able to put the dropdown item at left (it's at the right for the moment)
When I check an item on the dropdown list, my dropdown hide itself. I want that the dropdown keep its showing state.
How can I achieve what I want ?
P.S : As you can read, English is not my native language. These problems are difficult to explain (even in my native language), so if some sentences are not understandable, please tell me and I will try to improve them.
I suggest doing the simplest thing possible: remove all the ActionBarSherlock related code and add your own views in layout and program them to animate, pop-up, show and hide.