Applying a theme to a menu item? - android

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

Related

android toolbar menu item button?

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.

Adding a dropdown menu from a click event in the action bar in xamarin forms android

I added a toolbar item in my content page:
<ContentPage.ToolbarItems>
<ToolbarItem IconImageSource="icon_dropdown.png"/>
</ContentPage.ToolbarItems>
What I want to have is when a user clicks on the toolbar item, a menu pops down like this. Animated in a way where it slides down revealing the content/menu items.
I've been searching online but the keywords being searched always takes me to spinner, and being new to C# and Xamarin Forms, I am unsure if a spinner is still what I want to achieve something like this because a spinner looks more of a dialog box.
Sample image of what I'm trying to do that I've photoshopped
Any help is highly appreciated. Thanks.
I did some investigation, and find a way to change the position of the overflow popmenu by theme(code attached at the end in case you need it), but unable to change the width to match the whole screen, not sure if Android made some limitations in menu.
If you need a drop down list exact the same of your picture, spinner may not be a perfect choice either, you'd better create a new activity that overlays origin activity and customize the new activity layout, but it's not recommended considering performance. Also, you can find something in an earlier post to see if it gives you any idea.
add a new style:
<style name="OverflowMenuStyle" parent="#style/ThemeOverlay.AppCompat.Light">
<item name="overlapAnchor">false</item><!--not overlay the toolbar-->
<!--<item name="android:dropDownWidth">10dp</item> not work-->
<!--<item name="android:maxWidth">400dp</item> not work-->
<item name="android:paddingRight">0dp</item>
<!--dropDownVerticalOffset is the property you want to avoid overlay the toolbar-->
<item name="android:dropDownVerticalOffset">4dp</item>
<item name="android:dropDownHorizontalOffset">0dp</item>
<item name="android:popupBackground">#BFBFBF</item>
</style>
Android Resource layout folder's Toolbar.xml, change popupTheme to:
android:popupTheme="#style/OverflowMenuStyle"
add an item in MainTheme.Base style:
<item name="actionOverflowMenuStyle">#style/OverflowMenuStyle</item>

How to change Background color of menuItem in android?

I am working on programmatically add a menu-Item into menu. I want to add background color on selection to particular Item. How can I add background to menuItem?
Your answer would be appreciated.
While other answers provide change style (which will affect all menu items, and, as I understand, need is to change one menu item),I propose you to use android:actionLayout attribute to implement your custom layour for menu item.
See documentation for it (search actionLayout there, it's very simple actually).
Also I think there is a possibility to make a selector as your layout and use it.
Update. Sorry, I mislead you :(
All of this will work only if MenuItem is shown as Action (not when pressing on three dots).
Seems like guys given other answers were right - the only way to customize this is changing themes.
But please check this and this - it might help you to provide selector for your purpose.
Also you can create PopupMenu or even PopupWindow, last one is fully customizable.
The last option is to create custom Spinner, check this.
Hope something from this will help you. Thanks.
Firstly You need to create an Style for popmenu as you want refer below sample for that
<style name="MyApp.PopupMenu" parent="android:Widget.Holo.Light.ListPopupWindow">
<item name="android:textStyle">#style/commonEditTextTheme</item>
<item name="android:popupBackground">#drawable/pop_up_menu_bg_with_shadow</item>
</style>
Place of drawable you can also replace with color as you needed or make XML Drawable into your drawable folder
<style name="commonEditTextTheme" parent="#android:style/TextAppearance.Medium">
<item name="android:fontFamily">sans-serif-light</item>
</style>
this pop menu theme add in your main application or activity theme like below
<!--My Theme-->
<style name="MyTheme" parent="#android:style/Theme.Holo.Light">
......
<item name="android:popupMenuStyle">#style/MyApp.PopupMenu</item>
</style>

Customizing Up/Back/Burger background in my ActionBar

I'm trying to customize the background of my action bar items with a selector, to override what is shown when the button is pressed.
This was pretty easy with menu buttons (e.g., overflow icon), as you can style them with actionBarItemBackground .
Sadly this does not apply for the up/home/left indicator. I have unsuccessfully tried, in my styles.xml:
<item name="actionButtonStyle">;
<item name="actionBarStyle">;
<item name="toolbarStyle">;
None of the nested attributes seem to act on the home icon background. I also searched over android.R.attr and gave a look at this. Is there any way?
I would like to stay with the "up" indicator, without inflating a custom view. In that case, I would also have to inflate the title as well as custom views naturally appear at the end of the title. AND I would lose the burger-to-arrow animation, AND I would have to take care about margins and design guidelines (now managed by AppCompat), and some other bad thing on the way.
I thought about setting a Logo, but that would have some complications as well and I don't think I could change the background anyway.
I thought about Toolbar being a Layout, so I could put custom views in it from XML. If I'm not wrong they appear after the title, so neither this is a good idea.
What can I do?
please let me know if it works
add this to your your theme or if it doesn't take both remove the one with android prefix
<item name="android:selectableItemBackground">#drawable/selector</item>
<item name="selectableItemBackground">#drawable/selector</item>
Example #drawable/selector:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:state_pressed="true"
android:drawable="#ddffffff" />
<item
android:drawable="#android:color/transparent" />
</selector>

Android Sub-Menu Items Have Extra White Space To Right of Icon

I have an Android sub-menu, declared with this code:
<item
android:icon="#drawable/ic_menu_share"
android:showAsAction="ifRoom"
android:title="Share">
<menu>
<item
android:id="#+id/menuSortNewest"
android:icon="#drawable/ic_menu_share"/>
<item
android:id="#+id/menuSortRating"
android:icon="#drawable/ic_menu_share"/>
</menu>
</item>
The problem is that each item in the menu is an icon with a bunch of extra white space to the right of the icon. I just want the icon with no white space beside it. How do I achieve that?
Here is a screenshot of the application:
OP, As per the discussion in the comments, it's likely you'll need to create your own PopUpMenu to get the functionality you desire, please see:
http://stackoverflow.com/a/21329225/1067946
For info on doing it.

Categories

Resources