private void showServiceWeb(String content){
View localView = LayoutInflater.from(context).inflate(R.layout.layout_dialog_service_content, null);
Dialog dialog = utilsManage.dialog(this, localView, Gravity.CENTER, false);
ImageView img=localView.findViewById(R.id.service_img_cancel);
LinearLayout layout=localView.findViewById(R.id.service_layout);
Button btn=localView.findViewById(R.id.service_btn_ok);
img.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
finish();
}
});
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
dialog.dismiss();
}
});
initWebView(content,layout);
dialog.show();
}
private void initWebView(String content,LinearLayout layout){
// 设置屏幕自适应。
// webView=new WebView(context);
//创建一个LayoutParams宽高设定为全屏
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
//创建WebView
// if (webView != null) {
// Log.e(TAG, "initWebView !null: ");
// Toast.makeText(context, "webview不为空", Toast.LENGTH_SHORT).show();
// return;
// }
WebView webView = new WebView(context);
//设置WebView的宽高
webView.setLayoutParams(layoutParams);
//把webView添加到容器中
layout.addView(webView);
webView.getSettings().setUseWideViewPort(true);
webView.getSettings().setLoadWithOverviewMode(true);
// webView.getSettings().setDefaultFontSize(56);
// webView.getSettings().setMinimumFontSize(40);//设置最小字体
webView.getSettings().setTextZoom(300);//设置字体大小
// 建议禁止缓存加载,以确保在攻击发生时可快速获取最新的滑动验证组件进行对抗。
webView.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);
// 设置不使用默认浏览器,而直接使用WebView组件加载页面。
webView.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
});
webView.loadDataWithBaseURL(null,content, "text/html", "utf-8", null);//解决乱码问题
}
可参考布局:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#00ffffff">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:gravity="center"
android:layout_marginRight="30dp"
android:layout_marginLeft="30dp"
android:orientation="vertical"
android:background="@drawable/btn_white_background_small_rediu">
<TextView
android:layout_marginTop="30dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="用户协议及隐私政策"
android:textStyle="bold"
android:textSize="@dimen/title_size"/>
<TextView
android:id="@+id/main_service_content"
android:padding="20dp"
android:layout_marginTop="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="感谢您信任并使用信达众商城!\n\n
我们非常重视您的个人信息和隐私保护,为了更好的保障你的个人权益,在您使用我们产品前,请您认真阅读
《用户协议》和《隐私政策》的全部内容,同意并接受全部条款后开始使用我们的产品和服务。\n\n
若选择不同意,将无法使用我们的产品和服务,并退出应用。"
android:textSize="@dimen/content_size"/>
<LinearLayout
android:layout_marginTop="10dp"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:padding="12dp"
android:gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textColor="@color/grey"
android:background="@drawable/btn_grey_line_left_rediu"
android:text="不同意"/>
<TextView
android:padding="12dp"
android:gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textColor="@color/blue"
android:background="@drawable/btn_grey_line_right_rediu"
android:text="同意"/>
</LinearLayout>
</LinearLayout>
</RelativeLayout>