I'm sure there's a better way to do this...but i couldn't figure it out. So here's what i came up with.
I created my own extension of Button
. And create components of MyButton
inside my xmls
.
<com.stackoverflow.android.example.MyButton android:text="@+id/Button01" android:id="@+id/Button01" android:layout_width="wrap_content" android:layout_height="wrap_content"></com.stackoverflow.android.example.MyButton>
You'll need to change every instance of Button
to com.stackoverflow.android.example.MyButton
.
package com.stackoverflow.android.example;
import android.content.Context;
import android.os.Handler;
import android.util.AttributeSet;
import android.util.Log;
import android.view.MotionEvent;
import android.view.ViewConfiguration;
import android.widget.Button;
public class MyButton extends Button {
final int MSG_MYBUTTON_HIGHLIGHT_ON = 0;
final int MSG_MYBUTTON_HIGHLIGHT_OFF = 1;
public MyButton(Context context, AttributeSet attrs) {
super(context, attrs);
}
Handler mHandler = new Handler(){
public void handleMessage(android.os.Message msg) {
switch (msg.what) {
case MSG_MYBUTTON_HIGHLIGHT_ON:
setPressed(true);
sendEmptyMessageDelayed(MSG_MYBUTTON_HIGHLIGHT_OFF, ViewConfiguration.getPressedStateDuration());
break;
case MSG_MYBUTTON_HIGHLIGHT_OFF:
setPressed(false);
default:
break;
}
};
};
public void performVirtualClick()
{
mHandler.sendEmptyMessage(MSG_MYBUTTON_HIGHLIGHT_ON);
performClick();
}
}
Call the performVirtualClick
function...that'll do.