简体   繁体   English

自动加载自定义键盘,而无需在Android中触摸EditText

[英]Load Custom KeyBoard Automatically without touching EditText in Android

I have defined CustomKeyBoard in keyboard.xml file under 'xml' folder and added this keyboard.xml in activity_layout.xml. 我已经在'xml'文件夹下的keyboard.xml文件中定义了CustomKeyBoard,并在activity_layout.xml中添加了这个keyboard.xml。 I want my CustomkKeyboard should be loaded automatically when my activity starts, but it is loading when i am touching EditText. 我希望我的活动开始时应该自动加载我的CustomkKeyboard,但是当我触摸EditText时就可以加载它。 My code is 我的代码是

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);
    }
}

Is there any way to load Custom Keyboard with out touching edittext? 有什么办法可以在不触碰edittext的情况下加载自定义键盘?

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

Animations start on views having the focus. 动画从具有焦点的视图开始。 Override `onWindowFocusChanged(boolean hasFocus). 覆盖onWindowFocusChanged(boolean hasFocus)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM