0

「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に触れずにカスタムキーボードをロードする方法はありますか?

4

2 に答える 2

0

アクティビティの onCreate() メソッドで showKeyboardWithAnimation() を呼び出すことができます。 edittext.requestfocus() も呼び出す必要があります。

于 2013-03-26T18:02:04.493 に答える
0

フォーカスのあるビューでアニメーションが開始されます。`onWindowFocusChanged(boolean hasFocus) をオーバーライドします。

于 2013-03-26T18:19:51.917 に答える