WebView and loadData showing white screen in Android Constraints Layout -
i trying use constraints , webview , loaddata , got white screen. when changed linearlayout worked. try linearlayout inside constraint, white screen. there solution work constraints? thanks;
mainactivity
package com.example.grady.webviewdemo; import android.os.bundle; import android.support.v7.app.appcompatactivity; import android.webkit.webview; public class mainactivity extends appcompatactivity { @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); webview mwebview = (webview) findviewbyid(r.id.mywebview); string myhtmlstring = "<html> <head><meta http-equiv=\"content-type\" content=\"text/html; charset=utf-8\"></head><body>" + "<h2>this html heading in android webview.</h2>\n" + "<p>this html paragraph in android webview.</p>\n" + "\n" + "<h4>following html table in webview</h4>\n" + "<table border=\"1\" width=\"100%\">\n" + " <tr>\n" + " <td>android</td>\n" + " <td>webview</td>\t\t\n" + " <td>100</td>\n" + " </tr>\n" + " <tr>\n" + " <td>android</td>\n" + " <td>webview</td>\t\t\n" + " <td>200</td>\n" + " </tr>\n" + " <tr>\n" + " <td>android</td>\n" + " <td>webview</td>\t\t\n" + " <td>300</td>\n" + " </tr>\n" + "</table>" + "</body></html>"; mwebview.loaddata(myhtmlstring, "text/html; charset=utf-8", null); } } activity_main.xml
<?xml version="1.0" encoding="utf-8"?> <android.support.constraint.constraintlayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="com.example.grady.webviewdemo.mainactivity"> <linearlayout android:layout_width="match_parent" android:layout_height="match_parent"> <webview android:id="@+id/mywebview" android:layout_width="fill_parent" android:layout_height="fill_parent" /> </linearlayout> </android.support.constraint.constraintlayout>
the code provided working me. can try this:
xml:
<android.support.constraint.constraintlayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:id="@+id/root" android:layout_width="match_parent" android:layout_height="match_parent"> <webview android:id="@+id/mywebview" android:layout_width="match_parent" android:layout_height="match_parent" app:layout_constraintbottom_tobottomof="parent" app:layout_constraintleft_toleftof="parent" app:layout_constraintright_torightof="parent" app:layout_constrainttop_totopof="parent" /> </android.support.constraint.constraintlayout> gradle:
compile 'com.android.support.constraint:constraint-layout:1.0.2' 
Comments
Post a Comment