也许尝试完全省略xml属性android:editable,然后尝试以下组合
保持光标闪烁并防止触摸事件弹出本机IME(键盘)..
/*customized edittext class
* for being typed in by private-to-your-app custom keyboard.
* borrowed from poster at https://stackoverflow.com/questions/4131448/android-how-to-turn-off-ime-for-an-edittext
*/
public class EditTextEx extends EditText {
public EditTextEx(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
public boolean onCheckIsTextEditor() {
return false; //for some reason False leads to cursor never blinking or being visible even if setCursorVisible(true) was called in code.
}
}
第2步
改变上面的方法说return true;
第3步
在上面的类中添加另一种方法.
@Override
public boolean isTextSelectable(){
return true;
}
第4步
在已经实例化该类的实例并调用viewB的另一个位置,我添加了一个新的触摸事件处理程序
viewB.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View view, MotionEvent event) {
viewB.setCursorVisible(true);
return false;
}
});
步骤5检查以确保XML和/或EditText实例化代码将IME /键盘类型声明为“无”.我没有确认相关性,但我也使用下面的可聚焦属性.
android:id="@+id/editText1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:focusable="true"
android:focusableInTouchMode="true"
android:inputType="none">
很抱歉这么多xml属性.我的代码全部使用它们,在4.2.1中进行测试,并且有结果.
希望这可以帮助.