我创建了一个自定义键盘,按下我想移动到下一个 EditText 的键
I created a custom keyboard, on pressing down key I want to move to the next EditText
这是我的自定义键盘:
按下键后我想移动到下一个文本视图。向上键移动上一个文本视图的情况相同。
这是我的代码 keyboard.xml:
<Keyboard xmlns:android="http://schemas.android.com/apk/res/android"
android:keyWidth="15%p" android:horizontalGap="2dp"
android:verticalGap="2dp" android:keyHeight="40dip"
>
<Row>
<Key android:codes="8" android:keyLabel="1" android:keyEdgeFlags="left"
/>
<Key android:codes="9" android:keyLabel="2" />
<Key android:codes="10" android:keyLabel="3" />
<Key android:codes="11" android:keyLabel="4" />
<Key android:codes="12" android:keyLabel="5" />
<Key android:codes="67" android:keyIcon="@drawable/sym_keyboard_delete"
android:isRepeatable="true"
/>
<Key android:codes="55005" android:keyLabel="up"
android:keyEdgeFlags="right"
/>
</Row>
<Row>
<Key android:codes="13" android:keyLabel="6" android:keyEdgeFlags="left" />
<Key android:codes="14" android:keyLabel="7" />
<Key android:codes="15" android:keyLabel="8" />
<Key android:codes="16" android:keyLabel="9" />
<Key android:codes="7" android:keyLabel="0" />
<Key android:codes="-3" android:keyLabel="hide"
/>
<Key android:codes="66" android:keyLabel="down" android:keyEdgeFlags="right"
/>
</Row>
</Keyboard>
这是 onkey() 方法
@Override
public void onKey(int primaryCode, int[] keyCodes) {
long eventTime = System.currentTimeMillis();
KeyEvent event = new KeyEvent(eventTime, eventTime,
KeyEvent.ACTION_DOWN, primaryCode, 0, 0, 0, 0,
KeyEvent.FLAG_SOFT_KEYBOARD | KeyEvent.FLAG_KEEP_TOUCH_MODE);
mTargetActivity.dispatchKeyEvent(event);
}
code:66 正在执行输入功能但没有移动到下一个文本视图
谁能指导我如何实现这一目标
这是主要思想,您必须根据需要对其进行自定义
将以下内容添加到您的 XML 布局中
<EditText android:id="@+id/txt1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
(( android:imeOptions="actionNext"))/>
和
txt1.setOnKeyListener(new OnKeyListener() {
public boolean onKey(View v, int keyCode, KeyEvent event) {
// If the event is a key-down event on the "enter" button
if ((event.getAction() == KeyEvent.ACTION_DOWN) &&
(keyCode == KeyEvent.KEYCODE_ENTER))
{
// Perform action on Enter key press
txt1.clearFocus();
txt2.requestFocus();
return true;
}
return false;
}});
这是我的自定义键盘:
按下键后我想移动到下一个文本视图。向上键移动上一个文本视图的情况相同。
这是我的代码 keyboard.xml:
<Keyboard xmlns:android="http://schemas.android.com/apk/res/android"
android:keyWidth="15%p" android:horizontalGap="2dp"
android:verticalGap="2dp" android:keyHeight="40dip"
>
<Row>
<Key android:codes="8" android:keyLabel="1" android:keyEdgeFlags="left"
/>
<Key android:codes="9" android:keyLabel="2" />
<Key android:codes="10" android:keyLabel="3" />
<Key android:codes="11" android:keyLabel="4" />
<Key android:codes="12" android:keyLabel="5" />
<Key android:codes="67" android:keyIcon="@drawable/sym_keyboard_delete"
android:isRepeatable="true"
/>
<Key android:codes="55005" android:keyLabel="up"
android:keyEdgeFlags="right"
/>
</Row>
<Row>
<Key android:codes="13" android:keyLabel="6" android:keyEdgeFlags="left" />
<Key android:codes="14" android:keyLabel="7" />
<Key android:codes="15" android:keyLabel="8" />
<Key android:codes="16" android:keyLabel="9" />
<Key android:codes="7" android:keyLabel="0" />
<Key android:codes="-3" android:keyLabel="hide"
/>
<Key android:codes="66" android:keyLabel="down" android:keyEdgeFlags="right"
/>
</Row>
</Keyboard>
这是 onkey() 方法
@Override
public void onKey(int primaryCode, int[] keyCodes) {
long eventTime = System.currentTimeMillis();
KeyEvent event = new KeyEvent(eventTime, eventTime,
KeyEvent.ACTION_DOWN, primaryCode, 0, 0, 0, 0,
KeyEvent.FLAG_SOFT_KEYBOARD | KeyEvent.FLAG_KEEP_TOUCH_MODE);
mTargetActivity.dispatchKeyEvent(event);
}
code:66 正在执行输入功能但没有移动到下一个文本视图 谁能指导我如何实现这一目标
这是主要思想,您必须根据需要对其进行自定义
将以下内容添加到您的 XML 布局中
<EditText android:id="@+id/txt1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
(( android:imeOptions="actionNext"))/>
和
txt1.setOnKeyListener(new OnKeyListener() {
public boolean onKey(View v, int keyCode, KeyEvent event) {
// If the event is a key-down event on the "enter" button
if ((event.getAction() == KeyEvent.ACTION_DOWN) &&
(keyCode == KeyEvent.KEYCODE_ENTER))
{
// Perform action on Enter key press
txt1.clearFocus();
txt2.requestFocus();
return true;
}
return false;
}});