1.需要某个控件具有焦点 在布局里添加属性
android:focusable="true"
android:focusableInTouchMode="true"
2.状态选择器<?xml version="1.0" encoding="utf-8"?>
<selector
xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_focused="true" android:drawable="@drawable/hover_btn_confirm" />
<item android:drawable="@drawable/normal_btn_confirm" />
</selector>
3.焦点事件的处理
btnEtherSubmit
.setOnFocusChangeListener(new android.view.View.OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
if (hasFocus) {
// 此处为得到焦点时的处理内容
if (v.isInTouchMode()) {
// 此处为touchmode执行的内容,否则就会只是选中。
}
} else {
// 此处为失去焦点时的处理内容
}
}
});