我已在'xml'文件夾下的keyboard.xml文件中定義了CustomKeyBoard,並在activity_layout.xml中添加了此keyboard.xml。我希望我的CustomkKeyboard應該在我的活動開始時自動加載,但是當我觸摸EditText時它正在加載。我的代碼是自動加載自定義鍵盤而無需觸摸Android中的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?
直接從onCreate()調用'showKeyboardWithAnimation();'? – 2013-03-26 17:57:08