gpt4 book ai didi

Android 软键盘无法在 webView 中打开`

转载 作者:塔克拉玛干 更新时间:2023-11-02 07:57:22 25 4
gpt4 key购买 nike

我正在使用 AlertDialog 中的 WebView 对 Twitter 用户进行身份验证。但是当我点击 webview 中的字段时,android 键盘没有打开。这是我的代码,显示了我如何在警报对话框中添加 webview。我隐式调用了 android 键盘,但它在警报对话框后面打开了键盘。

这是我的代码。

public static void webViewDialog(final String authorizationURL, final int type)
{

final boolean correctPin;
System.out.println("In webViewDialog");
container = new LinearLayout(context);
container.setOrientation(LinearLayout.VERTICAL);

container.setMinimumWidth(200);
container.setMinimumHeight(320);

webView = new WebView(context);
webView.setMinimumWidth(200);
webView.requestFocusFromTouch();
webView.setMinimumHeight(380);
webView.getSettings().setJavaScriptEnabled(true);
webView.setWebViewClient(new TwitterWebViewClient());
webView.loadUrl(authorizationURL);
webView.setBackgroundColor(0xFFbbd7e9);
container.addView(webView);

Builder webDialog = new AlertDialog.Builder(context);

webDialog.setView(container).setTitle("Twitter Login")
.setPositiveButton("Ok", new DialogInterface.OnClickListener()
{

@Override
public void onClick(DialogInterface dialog, int which)
{

if (type == 0)
{
twitterPinCodeDialog();
dialog.dismiss();

}
}
}).show();
showVirtualKeyboard();

}
public static void showVirtualKeyboard()
{
Timer timer = new Timer();
timer.schedule(new TimerTask()
{

@Override
public void run()
{
InputMethodManager m = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);

if(m != null)
{
// m.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS);
m.toggleSoftInput(0, InputMethodManager.SHOW_IMPLICIT);
}
}

}, 100);
}

最佳答案

这是我对这个问题的解决方案:

放置一个虚拟编辑文本,并将其可见性设置为GONE,并将其添加到包含 LinearLayout 中,在将 WebView 添加到布局中之后。

例子:

AlertDialog.Builder builder = new AlertDialog.Builder(this);

LinearLayout wrapper = new LinearLayout(this);
WebView webView = new WebView(this);
EditText keyboardHack = new EditText(this);

keyboardHack.setVisibility(View.GONE);

webView.loadUrl(url);

wrapper.setOrientation(LinearLayout.VERTICAL);
wrapper.addView(webView, LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT);
wrapper.addView(keyboardHack, LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);

builder.setView(wrapper);

builder.create().show();

一旦完成,一切都应该正常工作,当您在 WebView 中选择一个项目时,键盘会按预期出现。

关于Android 软键盘无法在 webView 中打开`,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7252832/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com