How to change three dots button on android to other button - android

I wanna change the three dots button on Android to other button which is an "Add" button. How to do it? I have changed set the button in my drawable, but it keep prompt the three dot button.
Thanks

Sorry i can't reply as a comment, but i'm guessing you want to change the actionbar overflow menu icon. If so you can do it in styles.xml.
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
<item name="android:actionOverflowButtonStyle">#style/MyActionButtonOverflow</item>
</style>
<!-- Style to replace actionbar overflow icon. set item 'android:actionOverflowButtonStyle' in AppTheme -->
<style name="MyActionButtonOverflow" parent="android:style/Widget.Holo.Light.ActionButton.Overflow">
<item name="android:src">#drawable/ic_launcher</item>
</style>
Original post: How to change option menu icon in the action bar?

Sorry I don't have enough reputation to post a comment. Here is the best answer I found, its one line of code:
myToolbar.setOverflowIcon(ContextCompat.getDrawable(getApplicationContext(),R.drawable.my_drawable));
The link for the original answer is here:
https://stackoverflow.com/a/35790470/4575772

If you want to add other icon instead of 3 dots then just create menu.xml like below code:
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item android:id="#+id/menu_item_add"
android:title="Add"
app:showAsAction="always"
android:icon="#drawable/ic_add" />
</menu>
Note:
Don't use android:showAsAction.
Use app:showAsAction.

//just edit menu.xml file
//add icon for item which will change default setting icon
//add sub menus
///menu.xml file
<item
android:id="#+id/action_settings"
android:orderInCategory="100"
android:title="#string/action_settings"
android:icon="#drawable/your_icon"
app:showAsAction="always" >
<menu>
<item android:id="#+id/action_menu1"
android:icon="#android:drawable/ic_menu_preferences"
android:title="menu setting" />
<item android:id="#+id/action_menu2"
android:icon="#android:drawable/ic_menu_help"
android:title="help" />
</menu>
</item>

hope this help u, just set your xml menu like this:
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:icon="#drawable/your_icon"
android:title="menu"
app:showAsAction="always">
<menu>
<item
android:id="#+id/action_menu1"
android:orderInCategory="1"
android:title="menu 1" />
<item
android:id="#+id/action_menu2"
android:orderInCategory="2"
android:title="menu 2" />
</menu>
</item>
</menu>

For those who use Kotlin:
toolbar.overflowIcon = ContextCompat.getDrawable(applicationContext,android.R.drawable.ic_dialog_info)
Note: "ic_dialog_info" is an icon example.

Related

How to change Item title background in the navigation drawer in Android?

I have have a group of items in a navigation drawer menu:
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:title="Group Title">
<menu>
<group android:checkableBehavior="single">
<item
android:id="#+id/nav_camera"
android:icon="#drawable/ic_star_black_24dp"
android:title="Import" />
<item
android:id="#+id/nav_gallery"
android:icon="#drawable/ic_share_black_24dp"
android:title="Gallery" />
</group>
</menu>
</item>
</menu>
I managed to style the menu items following the instruction in this post from stack overflow. Basically modifying these three properties:
This works fine except it only styles the items inside the tag:
So my question is: how can I style (color and background) the titles ("Show Apps" and "Others")?
add following codes in styles.xml
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="android:itemBackground">#00F</item>
<item name="android:itemTextAppearance">#style/TextAppearance</item>
</style>
<style name="TextAppearance">
<item name="android:textColor">#F00</item>
</style>
change first line "name" and "parent" with your app defaults

android : set custom layout for actionbar overflow menu

In my application need to set a custom layout for the actionbar overflow menu as shown in the image, need suggestions how to achieve this.
You can edit your menu.xml according to your need. Below is just an example to show it is done
<item android:id="#+id/menu_save"
android:icon="#drawable/icon_save"
android:title="Save" />
<item android:id="#+id/menu_search"
android:icon="#drawable/icon_search"
android:title="Search" />
<item android:id="#+id/menu_share"
android:icon="#drawable/icon_share"
android:title="Share" />
<item android:id="#+id/menu_delete"
android:icon="#drawable/icon_delete"
android:title="Delete" />
<item android:id="#+id/menu_preferences"
android:icon="#drawable/icon_preferences"
android:title="Preferences" />
Edit the following code in your menu.xml file
<item
android:id="#+id/help"
android:title="Help"
app:showAsAction="never"
android:orderInCategory="100"/>
<item
android:id="#+id/Chng_pswd"
android:title="Change Password"
app:showAsAction="never"
android:orderInCategory="200"/>
<item
android:id="#+id/logout"
android:title="LogOut"
app:showAsAction="never"
android:orderInCategory="300"/>
Add this in your menu.xml items you want to display in your actionBar overflow menu:
app:showAsAction="never"
#Emzor
How to set custom layout for the menu , I have given app:showAsAction="never" for the menu items , It is displayed as in
How to set custom layout for the menu ? I have to show options as in the Image which is present in my question.

how to make the toolbar option drop down menu item to have left side custom check mark

In the toolbar's dropdown option menu, does anyone know how to add left side check mark in the menu item?
It is similar behavior as to use <group>, but the <group> gives a default radio button in the right side of the menu item. Thanks!
You can use setGroupCheckable()
EDIT-1:
use the following code:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<group android:checkableBehavior="all">
<item android:id="#+id/red"
android:title="#string/red" />
<item android:id="#+id/blue"
android:title="#string/blue" />
</group>
</menu>
The checkableBehavior="all" converts it into checkboxes.
Edit-2:
I had posted the following code somewhere.. Refer to get started on how to customize action bar menu items :
in your style file, place the following: 
<style name="MyAppTheme" parent="#android:style/Theme.Holo.Light">
<item name="android:actionBarStyle">#style/MyActionBar</item>
<item name="android:titleTextStyle">#style/MyActionBar.TitleTextStyle
<item name="android:actionMenuTextAppearance">#style/MyActionBar.MenuTextStyle</item>
<item name="android:actionMenuTextColor">#color/action_bar_red</item> </style>
<style name="MyActionBar.TitleTextStyle" parent="android:style/TextAppearance.Holo.Widget.ActionBar.Title"> <item name="android:textColor">#F0F</item> <item name="android:textStyle">bold</item>
<item name="android:textSize">24dip</item> </style>
<style name="MyActionBar.MenuTextStyle" parent="android:style/TextAppearance.Holo.Widget.ActionBar.Menu"> <item name="android:textColor">#F0F</item> <item name="android:textStyle">bold</item>
<item name="android:textSize">24dip</item>
</style>
You can make changes in the above style items to suit your requirements. I have not added separate styling for color though. As you might observe, I am just assigning red color (which I have declared in my colors file) to it. You may change as required.

Set icon to the group in options menu

I want to show a group of options in the menu, and need to change the standard three-lines icon to my own image. How can I achieve this? Group doesn't have an #icon option, unfortunately
menu.xml
<item
android:icon="#drawable/settings">
<group android:menuCategory="container">
<item
android:id="#+id/action_mute"
android:showAsAction="never"
android:title="#string/action_mute"/>
<item
android:id="#+id/action_add"
android:showAsAction="never"
android:title="#string/action_add"/>
<item
android:id="#+id/action_people"
android:showAsAction="never"
android:title="#string/action_people"/>
<item
android:id="#+id/action_more"
android:showAsAction="never"
android:title="#string/action_more"/>
</group>
</item>
It is called overflow button, if you want to change it you need to declare it in your style.xml located in the values folder.
Add this in your style.xml
<style name="Widget.ActionButton.Overflow" parent="#android:style/Widget.Holo.ActionButton.Overflow">
<item name="android:src">#drawable/your_drawable</item>
</style>
after you need to call it from you AppTheme
<style name="AppTheme" parent="//theme of your actionbar">
<item name="android:actionOverflowButtonStyle">#style/Widget.ActionButton.Overflow</item>
</style>

android sherlock actionbar menu selected item of menu with underline, color change

I'm using ActionBarSherlock, I have ActionBar like in picture:
I would like to change the blue color in e.g. green and I would like to have the selected item of menu with underline (so as in the picture).
My main_menu.xml:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="#+id/item0"
android:showAsAction="always"
android:title="#string/menu_item0">
</item>
<item
android:id="#+id/item1"
android:showAsAction="always"
android:title="#string/menu_item1">
</item>
<item
android:id="#+id/item2"
android:showAsAction="always"
android:title="#string/menu_item2">
</item>
<item
android:id="#+id/action_overflow"
android:icon="#drawable/ic_action_overflow"
android:showAsAction="always">
<menu>
<item android:id="#+id/contact" android:title="#string/submenu_0"/>
<item android:id="#+id/info" android:title="#string/submenu_1"/>
<item android:id="#+id/exit" android:title="#string/submenu_2"/>
</menu>
</item>
</menu>
How can I do it? In which file?
Not sure if you still need help with this but to change the underline on the action bar in action bar sherlock (abs) you just need to replace the background of the action bar with a 9-patch drawable that has a stretachable top seciton and a colour at the bottom (if you search for 'ad_tab_unselected_holo.png' in the abs sample code you can use this and just change the colour in the image).
You then need to att this png and change add the following to your style.xml (note we are changing both android:background & background for backwards compatability).
<style name="CustomTheme" parent="Theme.Sherlock">
<item name="android:actionBarStyle">#style/Widget.Styled.ActionBar</item>
</style>
<style name="Widget.Styled.ActionBar" parent="Widget.Sherlock.Light.ActionBar">
<item name="android:background">#drawable/ad_tab_unselected_holo</item>
<item name="background">#drawable/ad_tab_unselected_holo</item>
</style>
Then just apply this style in the manifest to your activity as follows;
<activity
android:label="#string/an_activity"
android:name="com.sample.TestActivity"
android:theme="#style/CustomTheme"/>

Categories

Resources