简体   繁体   English

为什么用WebView扩充布局时看不到软键盘?

[英]Why Can't I See The Soft Keyboard When I Inflate A Layout With A WebView?

I have a donation option on my app in the menu.我的应用程序在菜单中有一个捐赠选项。 When the user taps on that an AlertDialog.Builder appears that will display a layout with a webviewer on it.当用户点击它时,会出现一个 AlertDialog.Builder,它将显示一个带有 webviewer 的布局。 The page loads just fine in the WebViewer in the AlertDialog.该页面在 AlertDialog 的 WebViewer 中加载得很好。 However, when the webpage loads and there is a editable text view on the webpage the keyboard will not popup to allow users to enter in their dollar amount.然而,当网页加载并且网页上有可编辑的文本视图时,键盘不会弹出以允许用户输入他们的美元金额。 Here is what I tried...这是我试过的...

AlertDialog.Builder adb = new AlertDialog.Builder(MainActivity.this);
            adb.setIcon(R.drawable.ic_baseline_payment_32);
            adb.setTitle("Tip Developer");

            View v = getLayoutInflater().inflate(R.layout.tip_developer_layout, null);
            WebView wv = v.findViewById(R.id.tip_donation_webViewer);
            WebSettings ws = wv.getSettings();
            ws.setJavaScriptEnabled(true);

            wv.loadUrl("");

            wv.setWebViewClient(new WebViewClient() {

                public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {

                }

                public void onPageFinished(WebView view, String url) {
                    wv.requestFocusFromTouch();
                    wv.requestFocus(View.FOCUS_DOWN);
                }
            });

            wv.setOnTouchListener(new View.OnTouchListener() {
                @Override
                public boolean onTouch(View view, MotionEvent motionEvent) {
                    switch (motionEvent.getAction())
                    {
                        case MotionEvent.ACTION_DOWN:
                        case MotionEvent.ACTION_UP:
                            if (!v.hasFocus())
                            {
                                v.requestFocus();
                            }
                            break;
                    }
                    return false;
                }
            });


            adb.setPositiveButton("Close", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialogInterface, int i) {

                }
            });

            adb.setView(v);
            adb.create();
            adb.show();

I appreciate the help!感谢您的帮助!

Insert this code.插入此代码。

private void showSoftKeyBoard() {
        InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
    }

Then, implement it in OnCLick .然后,在OnCLick中实现它。

wv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                showSoftKeyBoard();
            }
        });

Add this line in your EditText.在您的 EditText 中添加这一行。

android:inputType="number"

And insert this code.并插入此代码。

@Override
    public void onResume() {
        super.onResume();
        wv.setFocusableInTouchMode(true);
        wv.requestFocus();
    }

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

相关问题 为什么我不能在布局包含片段的情况下为布局充气? - Why I can't inflate a layout where the layout contains a fragment? Java / Android:当我放置ScrollView时,会得到一个软键盘。 不能做一个好的布局 - Java/Android: When I put a ScrollView - I get a soft keyboard. Can't make a good layout 为什么我看不到Android应用程序的布局? - Why I dont't can see the Layout from a Android Application? 显示软键盘时布局不会向上移动 - Layout don't moves up when soft keyboard shown 无法以膨胀的布局书写 - Can't write in inflate layout 如何制作一个webview片段,我可以为多个diff网页充气 - how to make a webview fragment i can inflate for multiple diff webpages 为什么我在Android Studio中看不到布局预览,却看到一个“十字”符号并且无法添加任何元素? - Why can't I see the layout preview in Android Studio but instead I see a 'cross' sign and am not able to add any elements? 为什么当我按下“ Enter”键(不进行换行)时,Android软键盘会关闭 - Why does Android Soft Keyboard close when I press “Enter” (and not make a newline) 如何从 Java inflate 定位布局 ID - How can I target layout id from Java inflate 为什么我看不到 JList? - Why can't I see the JList?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM