WebView setBackgroundColor 在 Android 中不起作用
WebView setBackgroundColor not work in Android
我已经尝试了我发现的所有建议,但没有一个适合我。
此代码不影响 Android:
中 webview 的背景颜色
myWebView = (WebView) findViewById(R.id.webview1);
myWebView.setWebChromeClient(new WebChromeClient());
myWebView.getSettings().setJavaScriptEnabled(true);
myWebView.getSettings().setLoadWithOverviewMode(true);
myWebView.getSettings().setUseWideViewPort(true);
myWebView.getSettings();
myWebView.setBackgroundColor(0);
我怎样才能使作品具有如此简单的功能?
只需更改此
myWebView.setBackgroundColor(0);
至此
myWebView.setBackgroundColor(Color.BLUE);
因为它工作正常。
查看我的完整代码..
xml代码:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="com.example.softeng.abcd.Main2Activity"
tools:showIn="@layout/activity_main2"
>
<WebView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/webview"></WebView>
</RelativeLayout>
java代码。
WebView webview = (WebView)findViewById(R.id.webview);
webview.getSettings().setJavaScriptEnabled(true);
webview.getSettings().setLoadWithOverviewMode(true);
webview.getSettings().setUseWideViewPort(true);
webview.getSettings();
webview.setBackgroundColor(Color.BLUE);
输出:
我已经尝试了我发现的所有建议,但没有一个适合我。 此代码不影响 Android:
中 webview 的背景颜色myWebView = (WebView) findViewById(R.id.webview1);
myWebView.setWebChromeClient(new WebChromeClient());
myWebView.getSettings().setJavaScriptEnabled(true);
myWebView.getSettings().setLoadWithOverviewMode(true);
myWebView.getSettings().setUseWideViewPort(true);
myWebView.getSettings();
myWebView.setBackgroundColor(0);
我怎样才能使作品具有如此简单的功能?
只需更改此
myWebView.setBackgroundColor(0);
至此
myWebView.setBackgroundColor(Color.BLUE);
因为它工作正常。
查看我的完整代码..
xml代码:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="com.example.softeng.abcd.Main2Activity"
tools:showIn="@layout/activity_main2"
>
<WebView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/webview"></WebView>
</RelativeLayout>
java代码。
WebView webview = (WebView)findViewById(R.id.webview);
webview.getSettings().setJavaScriptEnabled(true);
webview.getSettings().setLoadWithOverviewMode(true);
webview.getSettings().setUseWideViewPort(true);
webview.getSettings();
webview.setBackgroundColor(Color.BLUE);
输出: