Show soft keyboard in AlertDialog with a WebView inside (Android)

后端 未结 3 2000
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-10 02:36

In my Android app I create an AlertDialog that has a WebView inside. The WebView loads a webpage that requires the user to log in. How

3条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-10 03:06

    There much better solution (with AlertDialog).

    1. Extend WebView class.

      public static class LocalWebView extends WebView {
          public LocalWebView(Context context) {
              super(context);
          }
      
          public LocalWebView(Context context, AttributeSet attrs) {
              super(context, attrs);
          }
      
          public LocalWebView(Context context, AttributeSet attrs, int defStyleAttr) {
              super(context, attrs, defStyleAttr);
          }
      
          @TargetApi(Build.VERSION_CODES.LOLLIPOP)
          public LocalWebView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
              super(context, attrs, defStyleAttr, defStyleRes);
         }
      
          public LocalWebView(Context context, AttributeSet attrs, int defStyleAttr, boolean privateBrowsing) {
              super(context, attrs, defStyleAttr, privateBrowsing);
          }
      
          @Override
          public boolean onCheckIsTextEditor() {
              return true;
          }
      }
      
    2. Use this LocalWebView instead of origin WebView in layout that you set to AlertDialog as content view.

提交回复
热议问题