How to achieve a ripple animation by clicking on a menu item? - android

I have a toolbar
There is a overflow that displays options in menu
On click of menu item, How to achieve a ripple animation
menu.xml
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="#+id/menuEventsTodayId"
android:title="#string/menu_events_today" />
<item android:id="#+id/menuUpcomingEventsId"
android:title="#string/menu_upcoming_events" />
<item android:id="#+id/menuSignOutId"
android:title="#string/menu_sign_out" />
</menu>
I tried with:
<item android:id="#+id/menuEventsTodayId"
android:background="?attr/actionBarItemBackground"
android:title="#string/menu_events_today" />
Its not working, How to properly achieve it

Just add the background as ?attr/selectableItemBackground. It will automatically give ripple on Android 5+

You can use following for android version above lollipop:
android:foreground="?attr/selectableItemBackground"
for prelollipop devices, you can use following:
compile 'com.balysv:material-ripple:1.0.2'

You need to define a separate style for your toolbar in the 'values' folder then add the following items to it:
<item name="selectableItemBackground">?android:selectableItemBackground</item>
<item name="android:colorControlHighlight">#color/ripple_material_dark</item>
Note:- As you can check this Link. ?android:selectableItemBackground is only properties which makes this animation.

Related

Add fontawesome icons in my toolbar items menu

I'm trying to add Font Awesome library to my android project but i just can't. I was reading each google result about this topic.
My menu.xml
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="#+id/buzon"
android:icon="#drawable/ic_buzon"
android:title="#string/buzon" />
<item
android:id="#+id/objetivos"
android:icon="#drawable/ic_objetivos"
android:title="#string/objetivos" />
<item
android:id="#+id/home_action"
android:icon="#drawable/ic_go_home"
android:title="#string/title_home" />
<item
android:id="#+id/encuesta"
android:icon="#drawable/ic_encuesta"
android:title="#string/encuesta" />
<item
android:id="#+id/cursos"
android:icon="#drawable/ic_cursos"
android:title="#string/cursos" />
</menu>
I'm want to use Font Awesome icons in my items menu instead default android icons.
For references, i was trying to follow this guide without success.
How to use Font Awesome icon in android application?

Android add buttons to ActionBar

I have a problem, in my app I need to add 2 buttons to the ActionBar, i change the menĂ¹ file in this way
<menu
xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="#+id/navigation_drawer"
android:icon="#drawable/ic_drawer"
android:title="Drawer"
android:showAsAction="ifRoom" />
<item android:id="#+id/info"
android:icon="#drawable/ic_info_outline_white_24dp"
android:title="info"
android:showAsAction="ifRoom" />
</menu>
but my items are in the overflow button without the image , only the text , how can I do to take off from there and make images appear on ActionBar ? it would be possible to put one on the left and one to the right of the name of the app ?
You can use android:showAsAction="always" to make them always show on the ActionBar.

Trying to color tabs on ActionBar

I am adding an actionbar to a test app I'm writing, and I see questions throughout stackoverflow about this, but nothing that has helped me at all. Based off of this guide:
http://android-developers.blogspot.com/2011/04/customizing-action-bar.html
I'm trying to change the select color for tabs that i'm using on my action bar. The default is that faint blue color. Just as a test I did this:
<style name="CustomTab" parent="android:style/Widget.Holo.Light.ActionBar.TabView">
<item name="android:background">#000000</item>
</style>
That gives me a solid black tab completely, not the selector part. Can someone help better direct me here? I can't seem to find a good example anywhere.
First you have to define a selector xml file then write this code there and replace your code with this
item name="android:background">#drawable/yourfilename</item>
and the selector xml
<?xml version="1.0" encoding="utf-8"?>
<selector
xmlns:android="http://schemas.android.com/apk/res/android"
>
<item
android:state_pressed="true"
android:drawable="#drawable/picture_selected" />
<item
android:state_focused="true"
android:drawable="#drawable/picture_selected" />
<item
android:drawable="#drawable/picture_unselected" />
</selector>

Android 3.0: Changing order of icons in the action bar

I am working with the Android 3.0.
I have in the action bar 3 items and one of them is the menu of the application, it also has sub-menu in it.
I want to change the order of the icons so the menu won't be in the right place, I want it to be between the two other items. I tried to change the order in the xml with no success.
Does anyone has an idea how to set the order?
Try setting android:menuCategory and android:orderInCategory for your menu items to set the ordering.
Example:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="#+id/launch_search"
android:icon="#android:drawable/ic_menu_search"
android:title="#string/search_programs"
android:menuCategory="container"
android:orderInCategory="2"
android:showAsAction="always" />
<item android:id="#+id/preferences_screen"
android:icon="#android:drawable/ic_menu_preferences"
android:title="#string/preferences" />
<item android:id="#+id/refresh"
android:icon="#drawable/ic_menu_refresh"
android:menuCategory="container"
android:orderInCategory="1"
android:title="#string/refresh_items"
android:showAsAction="ifRoom" />
</menu>
It will have the same effect as declaring launch_search -action as last, but this way you'll have your actions in the right order for 2.x and older devices while being able to control action ordering for 3.x -devices.
The menu will always go to the right, you cannot control its placement.

Different styles depending on button states? - Android

I have many custom buttons (ToggleButton) in my app and want to apply different styles for each button. I created a selector for all the buttons and I currently change only the drawable for the button, like this:
<?xml version="1.0" encoding="utf-8"?>
<selector
xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:state_checked="true"
android:drawable="#drawable/button_gradient_selected" />
<item
android:drawable="#drawable/button_gradient" />
</selector>
When I try to change the style the same way:
<item
android:state_checked="true"
android:drawable="#drawable/button_gradient_selected"
style="#style/button_checked />
It does not work, I have tried to change the drawable in the style instead (and just stated the style in the selector), I've also tried to create a separate selector but nothing seems to work.
Any ideas?
Right now it's not possible to do this.

Categories

Resources