Well you could use states of button for changing color like you want. For this approach you will need create a drawable xml file. Something like this(example from one of my project):
<?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" >
<solid android:color="@color/transparent_button_ripple_color"/>
</shape>
</item>
<item android:state_focused="true">
<shape android:shape="rectangle" >
<solid android:color="@color/transparent_button_ripple_color"/>
</shape>
</item>
<item android:state_enabled="false">
<shape android:shape="rectangle" >
<solid android:color="@color/transparent_button_ripple_color"/>
</shape>
</item>
<item >
<shape android:shape="rectangle" >
<gradient android:angle="-90" android:startColor="@color/colorTransparent" android:endColor="@color/colorTransparent" />
</shape>
</item>
</selector>
And them control the color by setting state to the button.
Also for representation of click in android you could add a ripple effect(Just for notice). https://guides.codepath.com/android/ripple-animation
Edited
I looked to your previous question and create the solution with respect of your code:
Create this method:
private void updateViewColorWithDelay(View targetView) {
targetView.setBackgroundColor(Color.parseColor("#000000"));
targetView.postDelayed(new Runnable() {
@Override
public void run() {
ivAvatar.setBackgroundColor(Color.parseColor("#ffffff"));
}
},300);
}
And use it with your views:
private class AutoDemoListener implements View.OnClickListener {
public void onClick(View v) {
Is_AutoDemo_B=true;
Out("AutoDemoListener");
switchView(demoView, registrationView);
startRegistration();
final Handler handler = new Handler();
registrationView.symbolButton[2][8].performClick();
updateViewColorWithDelay(registrationView.symbolButton[[2][8]);
handler.postDelayed(new Runnable() {
public void run() {
registrationView.symbolButton[4][13].performClick();
updateViewColorWithDelay(registrationView.symbolButton[4][13]);
}
}, 1000);
handler.postDelayed(new Runnable() {
public void run() {
registrationView.symbolButton[0][1].performClick();
updateViewColorWithDelay(registrationView.symbolButton[0][1]);
}
}, 3000);
handler.postDelayed(new Runnable() {
public void run() {
registrationView.symbolButton[6][18].performClick();
updateViewColorWithDelay(registrationView.symbolButton[6][18]);
}
}, 5000);
handler.postDelayed(new Runnable() {
public void run() {
Is_AutoDemo_B=false;
}
}, 5100);
}
}