原文:https://blog.csdn.net/uyy203/article/details/73991989
MainActivity.java
public class MainActivity extends AppCompatActivity {
private WebView wb;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
wb=(WebView) findViewById(R.id.webView);
WebSettings webSettings=wb.getSettings();
webSettings.setDefaultTextEncodingName("utf-8");
webSettings.setJavaScriptEnabled(true);//能够执行Javascript脚本
webSettings.setUseWideViewPort(false);//设置此属性,可任意缩放比例
webSettings.setTextZoom(100);//设置字体,相对于正常字体的百分比
webSettings.setDomStorageEnabled(true);//开启DOM storage
wb.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
return true;
}
});
}
}
activity_main.xml
<WebView
android:id="@+id/webView"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
在AndroidManifest.xml 中加入网络访问权限
<uses-permission android:name="android.permission.INTERNET"/>
网友评论