自动加载自定义KeyBoard而不触及Android中的EditText

时间:2013-03-26 17:50:04

标签: 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?

2 个答案:

答案 0 :(得分:0)

你可以在你的活动的onCreate()方法中调用showKeyboardWithAnimation()你也应该调用edittext.requestfocus()

答案 1 :(得分:0)

动画开始于具有焦点的视图。覆盖`onWindowFocusChanged(boolean hasFocus)。