如何在自定义键盘中一次处理Next和Done按钮,就像Android默认键盘一样。如果我的屏幕上有两个EditText
以下是我正在使用的代码。
<?xml version="1.0" encoding="utf-8"?>
<Keyboard xmlns:android="http://schemas.android.com/apk/res/android"
android:horizontalGap="0dp"
android:keyHeight="54dp"
android:keyWidth="25%p"
android:verticalGap="0dp" >
<Row>
<Key
android:codes="8"
android:keyEdgeFlags="left"
android:keyLabel="1" />
<Key
android:codes="9"
android:keyLabel="2" />
<Key
android:codes="10"
android:keyLabel="3" />
<Key
android:codes="69"
android:keyEdgeFlags="right"
android:keyLabel="-" />
</Row>
<Row>
<Key
android:codes="11"
android:keyEdgeFlags="left"
android:keyLabel="4" />
<Key
android:codes="12"
android:keyLabel="5" />
<Key
android:codes="13"
android:keyLabel="6" />
<Key
android:codes="56"
android:keyEdgeFlags="right"
android:keyLabel="." />
</Row>
<Row>
<Key
android:codes="14"
android:keyEdgeFlags="left"
android:keyLabel="7" />
<Key
android:codes="15"
android:keyLabel="8" />
<Key
android:codes="16"
android:keyLabel="9" />
<Key
android:codes="67"
android:iconPreview="@drawable/sym_keyboard_delete"
android:keyEdgeFlags="right"
android:keyIcon="@drawable/sym_keyboard_delete" />
</Row>
<Row>
<Key
android:codes="7"
android:keyLabel="0"
android:keyWidth="50%p" />
<Key
android:codes="66"
android:keyEdgeFlags="right"
android:keyLabel="Done"
android:keyWidth="50%p" />
</Row>
</Keyboard>
然后来到java代码
public CustomKeyboardView mKeyboardView;
private Keyboard mKeyboard;
private void setCustomKeyBoard(){
mKeyboard = new Keyboard(mContext, R.xml.keyboard);
mKeyboardView = (CustomKeyboardView) findViewById(R.id.keyboard_view);
mKeyboardView.setPreviewEnabled(false);
mKeyboardView.setKeyboard(mKeyboard);
mKeyboardView.setOnKeyboardActionListener(new BasicOnKeyboardActionListener(this));
}
并且在Manifest中我声明为
<activity
android:name="com.app.CommonActivity"
android:configChanges="keyboard|keyboardHidden|orientation"
android:windowSoftInputMode="adjustResize" />
答案 0 :(得分:0)
你不能设置两个底部,你首先禁用下一个按钮并替换为设置完成按钮
etname.setImeOptions(EditorInfo.IME_ACTION_DONE);
完整代码
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final EditText etname;
etname = (EditText) findViewById(R.id.edittext);
etname.setImeOptions(EditorInfo.IME_ACTION_DONE);
}
}
android:imeOptions="actionDone"
完整代码:
<EditText
android:id="@+id/etname"
android:textSize="18sp"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:imeOptions="actionDone" >
</EditText>