[英]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.