簡體   English   中英

在AlertDialog中顯示帶有WebView的軟鍵盤(Android)

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

在我的Android應用程序中,我創建了一個AlertDialog WebViewAlertDialog WebView加載需要用戶登錄的網頁。但是,當我單擊WebView文本字段時,不會出現軟鍵盤。 我一般都知道這個問題( Android:Issue 7189 ); 但是,在我的情況下,建議的解決方案似乎不起作用,因為我使用外部網站,而不僅僅是一個簡單的HTML表單。

如果用戶點擊網站的文本字段時出現鍵盤,那么完美的解決方案就是。 但是,讓鍵盤與AlertDialog一起顯示也可以。 有任何想法嗎?

似乎最好的解決方案是簡單地創建一個自定義對話框。 自定義對話框似乎根本沒有軟鍵盤錯誤(它完全顯示在必要時)。 這是一些基本代碼:

Dialog dialog = new Dialog(this);
dialog.requestWindowFeature(Window.FEATURE_LEFT_ICON);
dialog.setContentView(R.layout.dialog);
dialog.setTitle("My great title");
dialog.setCancelable(true);

dialog.show();
dialog.setFeatureDrawableResource(Window.FEATURE_LEFT_ICON, R.drawable.icon);

WebView vw = (WebView) dialog.findViewById(R.id.wv);

有更好的解決方案(使用AlertDialog)。

  1. 擴展WebView類。

     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. 在您將AlertDialog設置為內容視圖的布局中使用此LocalWebView而不是原始WebView。

如果它仍然相關,對我來說問題與沉浸式對話+ webview有關。

我通過在對話框窗口設置一個標志 - NOT FOCUS來覆蓋對話框show方法來實現身臨其境,一旦我刪除了它,我就失去了沉浸感但現在我的網頁對話框彈出了鍵盤......

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM