Android dialogFragment "sometimes" not displaying webview

I have a DialogFragment with a WebView inside it. If the web view does not load the page fast enough, DialogFragment is fully compressed and does not display the web view. Otherwise, if the download was fast, the WebView is displayed.

+8
android android-dialogfragment android-webview
source share
4 answers

I found a solution myself. If you use LinearLayout as the root view for your DialogFragment, this will happen, changing it to FrameLayout, fix the problem. I don’t understand why, but it works.

+9
source share

In my case, I used a custom WebView like ExpandableHeightWebView for dynamic height.

 @Override public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { if (isExpanded()) { int expandSpec = MeasureSpec.makeMeasureSpec(MEASURED_SIZE_MASK, MeasureSpec.AT_MOST); super.onMeasure(widthMeasureSpec, expandSpec); ViewGroup.LayoutParams params = getLayoutParams(); params.height = getMeasuredHeight(); } else { super.onMeasure(widthMeasureSpec, heightMeasureSpec); } } 

I call setExpanded(true); after myWebView.loadData(data,null);
This problem is resolved when I delete the line setExpanded(true); .

+1
source share

I tried on two devices.

In the first device, the Nexus 6 worked just like David. "I found the solution myself. If you use LinearLayout as the root view for your DialogFragment, this will happen by changing it to FrameLayout, solve the problem. I don’t understand why, but it works." But I tried in the second device (Galaxy Prime) and was surprised it did not work. After trying to make setVisible GONE WebView in my WebViewClient inside the onPageStarted() callback and after setVisible VISIBLE inside the onPageFinished() callback and it worked for mine.

 public class MyWebClient extends WebViewClient { private static final String LOG_CAT = "NetPayWebClient"; @Override public void onPageStarted(WebView view, String url, Bitmap favicon) { Log.e(LOG_CAT, "onPageStarted(): " + url); view.setVisibility(View.GONE); super.onPageStarted(view, url, favicon); } @Override public void onPageFinished(WebView view, String url) { Log.e(LOG_CAT, "onPageFinished(): " + url); view.setVisibility(View.VISIBLE); super.onPageFinished(view, url); } } 
+1
source share

If you can load the web view through AsyncTaks, the Dialog snippet is not displayed because AsyncTasks cannot change the layout that is in the main thread. Take a look at this.

0
source share

All Articles