您的位置:首页 > 其它

DialogFragment使用

2017-04-12 17:34 260 查看

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));
}
}

<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>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: