「xml」フォルダーの下のkeyboard.xmlファイルでCustomKeyBoardを定義し、このkeyboard.xmlをactivity_layout.xmlに追加しました。アクティビティの開始時に CustomkKeyboard を自動的にロードする必要がありますが、EditText に触れるとロードされます。私のコードは
private CustomKeyboardView mKeyboardView;
private View mTargetView;
private Keyboard mKeyboard;
mKeyboard = new Keyboard(this, R.xml.keyboard);
mTargetView = (EditText) findViewById(R.id.ed_2d_res);
mTargetView.setFocusable(true);
mTargetView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
showKeyboardWithAnimation();
return true;
}
});
mKeyboardView = (CustomKeyboardView) findViewById(R.id.keyboard_view);
mKeyboardView.setKeyboard(mKeyboard);
mKeyboardView.setOnKeyboardActionListener(new BasicOnKeyboardActionListener(this));
}
private void showKeyboardWithAnimation() {
if (mKeyboardView.getVisibility() == View.GONE) {
Animation animation = AnimationUtils.loadAnimation(Add2d.this, R.anim.slide_in_bottom);
mKeyboardView.showWithAnimation(animation);
}
}
edittextに触れずにカスタムキーボードをロードする方法はありますか?