0

我在“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的情况下加载自定义键盘?

4

2 回答 2

0

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

于 2013-03-26T18:02:04.493 回答
0

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

于 2013-03-26T18:19:51.917 回答