当我在TextEdit视图上使用键盘时,我想获取触摸信息(通过获取motionEvents而不仅仅是click,keyUp,...)。
我为这样的按钮视图解决了这个问题:
Button button = (Button) findViewById(R.id.buttonSubmit);
button.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
// Save event information (such as pressure, size,..) here
return false;
}
});
因此我尝试使用与KeyboardView相同的方法而没有运气
KeyboardView keyboard = (KeyboardView) findViewById(R.id.keyboardView);
keyboard.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
// Save event information (such as pressure, size,..) here
return false;
}
});
当键盘可见时,代码似乎永远不会进入onTouch函数。这是layout.xml
<EditText android:id="@+id/edit_answer1"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:gravity="top"
android:hint="@string/edit_answer" />
<Button
android:id= "@+id/buttonSubmit"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:text="@string/button_submit" />
<android.inputmethodservice.KeyboardView
android:id="@+id/keyboardView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:focusable="true"
android:focusableInTouchMode="true"
android:visibility="gone" />