DialogFragment使用

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){
            /**
             * 设置dialog的大小
             */
            DisplayMetrics dm = new DisplayMetrics();
            getActivity().getWindowManager().getDefaultDisplay().getMetrics(dm);
            dialog.getWindow().setLayout((int) (dm.widthPixels * 0.6), (int) (dm.heightPixels*0.7));
        }
    }



"http://schemas.android.com/apk/res/android" android:shape="rectangle">

    "10dp">
    "@color/white">

布局


<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>

你可能感兴趣的:(android)