I want the onClick()
animation to be there on the buttons.
I have already tried
myButton.setBackgroundResource(0)
and
myButton.setBackgroundColor(Color.TRANSPARENT)
but both of these disable the onClick()
animation.
I want the onClick()
animation to be there on the buttons.
I have already tried
myButton.setBackgroundResource(0)
and
myButton.setBackgroundColor(Color.TRANSPARENT)
but both of these disable the onClick()
animation.
You can create a drawable with <selector>
if you need to have control over your clickable item design.
If you only need to make your view transparent and apply system default pressed color, you can use AppCompat's selectableItemBackground
as following:
TypedValue outValue = new TypedValue();
getContext().getTheme().resolveAttribute(R.attr.selectableItemBackground, outValue, true);
myButton.setBackgroundResource(outValue.resourceId);
or in XML:
android:background="?attr/selectableItemBackground"
Check this question for further information.
You can create selector in drawable and can set as a button background.Here you can specify its stats pressed,focused etc.
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:state_pressed="true" >
<shape android:shape="rectangle" >
<corners android:radius="3dip" />
<stroke android:width="1dip" android:color="@color/theme_text_color" />
<gradient android:angle="-90" android:startColor="@color/blue_transparent" android:endColor="@color/blue_transparent" />
</shape>
</item>
<item android:state_focused="true">
<shape android:shape="rectangle" >
<corners android:radius="3dip" />
<stroke android:width="1dip" android:color="@color/theme_text_color" />
<solid android:color="@color/theme_text_color"/>
</shape>
</item>
<item >
<shape android:shape="rectangle" >
<stroke android:width="1dip" android:color="#00000000" />
<gradient android:angle="-90" android:startColor="#00000000" android:endColor="#00000000" />
</shape>
</item>
</selector>
In xml file
android:background="@drawable/selector_button"
or programatically
myButton.setBackgroundResource(R.drawable.selector_button);