44、自定义仿IOS对话框

44、自定义仿IOS对话框

private Dialog myDialog = null; private void ExitLogin() { View view = LayoutInflater.from(MainActivity.this).inflate(R.layout.activity_exit_dialog, null); Button btn_close = (Button) view.findViewById(R.id.btn_close); Button btn_ok = (Button) view.findViewById(R.id.btn_ok); ImageView img_close = (ImageView) view.findViewById(R.id.img_close); img_close.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { myDialog.dismiss(); } }); btn_close.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { myDialog.dismiss(); } }); btn_ok.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { myDialog.dismiss(); } }); myDialog = new Dialog(MainActivity.this, R.style.utils_dialog_loading_dialog_style); myDialog.setCancelable(false); myDialog.setContentView(view, new LinearLayout.LayoutParams( LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT)); myDialog.show(); }
 1 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"  2  android:layout_width="wrap_content"  3  android:layout_height="wrap_content"  4  android:background="@drawable/bg_dialog"  5  android:layout_centerHorizontal="true"  6  android:layout_centerVertical="true" >  7  8 <RelativeLayout  9 android:layout_width="280dp" 10  android:layout_height="wrap_content" 12  android:orientation="vertical" 13  android:id="@+id/pop_student" 14  android:layout_centerVertical="true" 15  android:layout_centerHorizontal="true"> 16 17 <TextView 18 android:id="@+id/txt01" 19  android:layout_width="wrap_content" 20  android:layout_height="wrap_content" 21  android:textColor="@android:color/black" 22  android:textSize="18sp" 23  android:text="确定要退出吗?" 24  android:layout_marginTop="50dp" 25  android:layout_marginBottom="40dp" 26  android:layout_alignParentTop="true" 27  android:layout_centerHorizontal="true" 28 /> 29 42 <LinearLayout 43 android:id="@+id/layout_01" 44  android:layout_below="@id/txt01" 45  android:layout_width="match_parent" 46  android:layout_height="wrap_content" 47  android:orientation="horizontal" > 50 <Button 51 android:id="@+id/btn_close" 52  android:layout_width="wrap_content" 53  android:layout_height="43dp" 54  android:layout_weight="1" 55  android:background="@drawable/bg_dialog_button_left" 56  android:gravity="center" 57  android:textColor="@android:color/black" 58  android:text="取消" 59  android:textSize="16sp" /> 60 61 <ImageView 62 android:id="@+id/img_line" 63  android:layout_width="0.5dp" 64  android:layout_height="43dp" 65  android:background="#c6c6c6" /> 66 67 <Button 68 android:id="@+id/btn_ok" 69  android:text="确认" 70  android:layout_width="wrap_content" 71  android:layout_height="43dp" 72  android:layout_weight="1" 73  android:background="@drawable/bg_dialog_button_right" 74  android:gravity="center" 75  android:textColor="@android:color/black" 76  android:textSize="16sp" 77  android:textStyle="bold" /> 78 </LinearLayout> 79 <View 80 android:layout_width="match_parent" 81  android:layout_height="1dp" 82  android:background="@color/hint" 83  android:layout_alignTop="@+id/layout_01" 84  android:layout_alignParentLeft="true" 85  android:layout_alignParentStart="true" /> 86 87 <ImageView 88 android:id="@+id/img_close" 89  android:layout_marginTop="10dp" 90  android:layout_marginRight="10dp" 91  android:layout_width="wrap_content" 92  android:layout_height="wrap_content" 93  android:src="@drawable/exit_dialog_close" 94  android:layout_alignParentTop="true" 95  android:layout_alignParentRight="true" 96  android:layout_alignParentEnd="true" /> 97 98 </RelativeLayout> 99 </RelativeLayout>
bg_dialog_button_left.xml
<?xml version="1.0" encoding="utf-8"?>



<selector xmlns:android="http://schemas.android.com/apk/res/android">

    <item>

        <shape android:shape="rectangle">

            <solid android:color="#ffffff" />

            <corners android:bottomLeftRadius="30dp" 

                android:bottomRightRadius="0dp"

                android:topLeftRadius="0dp" 

                android:topRightRadius="0dp" />

            <padding android:top="10dp" 

                android:bottom="10dp" 

                android:left="30dp"

                android:right="30dp" />

        </shape>

    </item>



    <item android:state_pressed="true">

        <shape android:shape="rectangle">

            <solid android:color="@color/code09" />

            <corners android:bottomLeftRadius="30dp" 

                android:bottomRightRadius="0dp"

                android:topLeftRadius="0dp" 

                android:topRightRadius="0dp" />

            <padding android:top="10dp" android:bottom="10dp" 

                android:left="30dp" android:right="30dp" />

        </shape>

    </item>

</selector>
 
  
bg_dialog_button_right.xml
<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item> <shape android:shape="rectangle"> <solid android:color="#ffffff" /> <corners android:bottomLeftRadius="0dp" android:bottomRightRadius="30dp" android:topRightRadius="0dp" android:topLeftRadius="0dp"/> <padding android:right="25dp" android:left="25dp" android:top="10dp" android:bottom="10dp" /> </shape> </item> <item android:state_pressed="true"> <shape android:shape="rectangle"> <solid android:color="@color/code09" /> <padding android:bottom="10dp" android:top="10dp" android:left="25dp" android:right="25dp"/> <corners android:bottomLeftRadius="0dp" android:bottomRightRadius="30dp" android:topRightRadius="0dp" android:topLeftRadius="0dp"/> </shape> </item> </selector>

 

 

你可能感兴趣的:(ios)