Android button drawing circle effect - android

Hey guys I just wanna ask question about the default button in android studio when you click it it has effect that it draw circle and fills the button but i wanna know how i can do that in custom button ? thanks for reading

Create a new file "res/drawable/ripple_effect.xml" then add this as background for the button through XML or dynamically.
i.e. android:background="#drawable/ripple_effect"
<?xml version="1.0" encoding="utf-8"?>
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:color="#f816a463"
tools:targetApi="lollipop">
<item android:id="#android:id/mask">
<shape android:shape="rectangle">
<solid android:color="#f816a463" />
</shape>
</item>
</ripple>

Related

How to add ripple animation to widget with custom background?

How to implement following hover (Ripple) in android?
I have a linear layout and i want when user touched the layout all widgets in linear layout become lighter.
Create a ripple drawable in res/drawable:
<?xml version="1.0" encoding="utf-8"?>
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:color="#color/ripple"
tools:targetApi="lollipop">
<item android:id="#android:id/mask">
<shape android:shape="rectangle">
<solid android:color="#color/ripple" />
<corners android:radius="#dimen/dp_6" />
</shape>
</item>
</ripple>
Set this drawable to the button foreground:
android:foreground = "#drawable/bg_btn_ripple_animation"
You can modify the ripple drawable as per your liking.

Add Ripple / Animation effect to an Android button but keep original customization

I have a custom button, and I need to create a Ripple effect. But after creating I do not know how I could combine the two effects.
I would like to have my original style and when I click add the ripple effect.
Original code before ripple:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#EEEEEE"></solid>
<corners android:radius="5dp"></corners>
<stroke android:width="1dp" android:color="#99FFFFFF"></stroke>
</shape>
Code ripple:
<?xml version="1.0" encoding="utf-8"?>
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:color="#f816a463"
tools:targetApi="lollipop">
<item android:id="#android:id/mask">
<shape android:shape="rectangle">
<solid android:color="#f816a463" />
<corners android:radius="5dp" android:color="#f816a463"></corners>
<stroke android:width="1dp" android:color="#f816a463"></stroke>
</shape>
</item>
<item
android:id="#android:id/background"
android:drawable="#android:color/holo_blue_bright">
</item>
</ripple>
Code Button:
<Button
android:id="#+id/btns2teste"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignStart="#+id/btnTestes"
android:layout_below="#+id/btnTestes"
android:layout_marginTop="49dp"
android:background="#drawable/ripple_effect"
android:text="Botao2" />
Image Button before:
When I created the new style and called in the xml of the button, I can no longer call the effect I created earlier, and it gets a simple button with ripple colors.
I would like to apply the ripple effect but keep the button state in the way I'd like it to be already custom with the border.
I need to find a way to combine the styles.

How to have a selectable background together with a certain color background?

I know that you would get a selectable (highlight/ripple) background for a view using this:
android:background="?attr/selectableItemBackground"
But what if I want a certain color background together with the ripple/highlight, what do I do?
(I'm hoping for a few lines of code not involving creating separate drawables which is very inelegant)
try this
<?xml version="1.0" encoding="utf-8"?>
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:color="#f816a463"
tools:targetApi="lollipop">
<item android:id="#android:id/mask">
<shape android:shape="rectangle">
<solid android:color="#f816a463" /> <--your custom color-->
</shape>
</item>
</ripple>
And then
android:background="#drawable/ripple_effect"
in your button

ripple effect coming without the background color

I am trying to implement ripple effect on my button and its working fine but the problem is the color of the button is gone , though i have given the color in the ripple.xml file , it just removed the color and showing the effect only . Also i am only able to user line and oval effect, unable to use ring and rectangle,
please suggest .
ripple.xml is below
<?xml version="1.0" encoding="utf-8"?>
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
android:color="?android:colorControlHighlight">
<item android:id="#android:id/mask">
<shape android:shape="rectangle">
<solid android:color="#A3080C" />
</shape>
</item>
</ripple>

Android Button setBackground() causes highlight effect to go away

I'm trying to programmatically add a background resource to a button but as soon as I do that, the highlight effect of when the button is clicked goes away. How do I restore the highlight effect while still using the background?
button_layout.xml:
<?xml version="1.0" encoding="utf-8"?>
<layer-list
xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:drawable="#layout/avail_button_solid" />
<item android:drawable="#layout/avail_button_shape" />
</layer-list>
avail_button_solid.xml:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#ababab" />
</shape>
avail_button_shape.xml:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#ffffff" />
<stroke android:width="1dp" android:color="#ff000000" />
</shape>
Java code:
b.setBackgroundResource(R.layout.button_layout);
The code sets the background but takes away the highlighting effect.
Buttons (and many other Android widgets) use a <selector> drawable (the analog in the SDK is a StateListDrawable). This is actually a Drawable container that maps different drawables to different states: pressed, focused, disabled, normal, etc. You should make one of these yourself if you want to replace the button background.
Read more about it here: http://developer.android.com/design/style/touch-feedback.html

Categories

Resources