1.布局中设置padding 如何不设置会被覆盖无法显示圆角
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
//去掉标题
getDialog().requestWindowFeature(Window.FEATURE_NO_TITLE)
//设置背景 圆角
getDialog().getWindow().setBackgroundDrawableResource(R.drawable.background)
View view = inflater.inflate(R.layout.news_webview, container, false)
WebView news_webview= (WebView) view.findViewById(R.id.news_webview)
news_webview.getSettings().setJavaScriptEnabled(true)
news_webview.loadUrl(loadUrl)
return view
}
@Override
public void onStart() {
super.onStart()
Dialog dialog=getDialog()
if (dialog!=null){
DisplayMetrics dm = new DisplayMetrics()
getActivity().getWindowManager().getDefaultDisplay().getMetrics(dm)
dialog.getWindow().setLayout((int) (dm.widthPixels * 0.6), (int) (dm.heightPixels*0.7))
}
}
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<corners android:radius="10dp"></corners>
<solid android:color="@color/white"></solid>
</shape>
布局
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:padding="5dp"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<WebView
android:padding="@dimen/margin15"
android:id="@+id/news_webview"
android:layout_width="match_parent"
android:background="@color/white"
android:layout_height="match_parent"></WebView>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@mipmap/set"
android:layout_marginTop="0dp"
android:layout_marginRight="0dp"
android:layout_alignRight="@+id/news_webview"
android:layout_alignParentRight="true"/>
</RelativeLayout>
</RelativeLayout>