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. The page loads just fine in the WebViewer in the AlertDialog. 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
.
wv.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
showSoftKeyBoard();
}
});
Add this line in your EditText.
android:inputType="number"
And insert this code.
@Override
public void onResume() {
super.onResume();
wv.setFocusableInTouchMode(true);
wv.requestFocus();
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.