• An overview of the
    • rendering
    • Custom rounded corner layout style
    • A reference to the main layout
    • Displays custom rounded layout

Summary:

This article focuses on solving the display problems of traditional dialog custom styles, such as setting a custom background with rounded corners, but rounded corners are not displayed, only rectangles, etc.

Effect:

Custom rounded corner layout style:

drawable/cleardialog_bg

<? The XML version = "1.0" encoding = "utf-8"? > <shape xmlns:android="http://schemas.android.com/apk/res/android" > <solid android:color="@color/white" /> <corners android:radius="15dp" /> </shape>Copy the code

A reference to the main layout

The android: background = “@ drawable/cleardialog_bg”

<? The XML version = "1.0" encoding = "utf-8"? > <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" ***android:background="@drawable/cleardialog_bg"*** android:clipChildren="false" android:orientation="vertical"> <LinearLayout android:id="@+id/rl_code" android:layout_width="match_parent" android:layout_height="100dp" android:layout_gravity="center" android:orientation="vertical"> <TextView android:id="@+id/temp" android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="3" android:gravity="center" android:text="@string/clearhistory" android:textColor="@color/item_name_color" android:textSize="@dimen/itme_name_size" /> <ImageView android:layout_width="match_parent" android:layout_height="1dp" android:background="@color/dialog_gray" /> <! <LinearLayout Android :layout_width="match_parent" Android :layout_height="0dp" android:layout_alignParentBottom="true" android:layout_weight="2" android:orientation="horizontal"> <TextView android:id="@+id/tv_canclecodet" android:layout_width="0dp" android:layout_height="match_parent" Android :layout_weight="1" Android :gravity="center" Android :text=" cancel "Android :textColor="@color/dialog_bluee" android:textSize="@dimen/text_size_large" /> <ImageView android:layout_width="1dp" android:layout_height="match_parent" android:background="@color/dialog_gray" /> <TextView android:id="@+id/tv_sure_codet" android:layout_width="0dp" Android :layout_height="match_parent" Android :layout_weight="1" Android :gravity="center" Android :text=" " android:textColor="@color/dialog_bluee" android:textSize="@dimen/text_size_large" /> </LinearLayout> </LinearLayout> </LinearLayout>Copy the code

Displays custom rounded layout

dialogWindow.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));

private void showClearHistoryDialog(){ // final Dialog dialog=new Dialog(this); dialog=new Dialog(this); dialog.setContentView(R.layout.clearhistorysearch_layout); // Custom dialog layout Window dialogWindow = dialog.getwindow (); WindowManager m = getWindowManager(); dialogWindow.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT)); Display d = m.getDefaultDisplay(); / / to get the screen width and height WindowManager. LayoutParams p = dialogWindow. GetAttributes (); P.eight = (int) (d.getheight () * 0.24); P.width = (int) (d.getwidth () * 0.65); / / screen width is set to 0.65, according to actual condition adjust dialogWindow. SetAttributes (p); dialog.show(); tv_canclecodet= (TextView) dialog.findViewById(R.id.tv_canclecodet); tv_sure_codet= (TextView) dialog.findViewById(R.id.tv_sure_codet); tv_canclecodet.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { dialog.dismiss();  }}); tv_sure_codet.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Logger. I (" Click confirm dialog "); }}); }Copy the code