[英]Load Custom KeyBoard Automatically without touching EditText in Android
我已經在'xml'文件夾下的keyboard.xml文件中定義了CustomKeyBoard,並在activity_layout.xml中添加了這個keyboard.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的情況下加載自定義鍵盤?
您可以在活動的onCreate()方法中調用showKeyboardWithAnimation(),也應調用edittext.requestfocus()
動畫從具有焦點的視圖開始。 覆蓋onWindowFocusChanged(boolean hasFocus)。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.