简体   繁体   English

单击文本框时,物理设备上的软键盘不显示

[英]Soft keyboard on physical device doesn't show when a textbox is clicked

I'm currently using Oppo F7 to test my app that I made using Android Studio. 我目前正在使用Oppo F7测试我使用Android Studio制作的应用程序。 However, when I tested it and I clicked on a textbox (or EditText), the keyboard doesn't show/pop-up. 但是,当我测试它并单击文本框(或EditText)时,键盘不显示/弹出。 Helpppp.. Helpppp ..

Note: 注意:
- My Oppo F7 is running on Android 8.1.0 (API 27) - 我的Oppo F7在Android 8.1.0上运行(API 27)
- It works on the emulator on my laptop but it's far to laggy for me to test -它可以在我的笔记本电脑上的仿真器上运行,但要我测试还远远不够

use like this 像这样用

public static void showSoftKeyboard(final Context context, final EditText editText) {
        try {
            editText.requestFocus();
            editText.postDelayed(
                    new Runnable() {
                        @Override
                        public void run() {
                            InputMethodManager keyboard = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
                            keyboard.showSoftInput(editText, 0);
                        }
                    }
                    , 200);
        } catch (NullPointerException npe) {
            npe.printStackTrace();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

in your activity call on text click 在您的活动中调用文本单击

showSoftKeyboard(this, yourEditTextToFocus);

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

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