AlertDialog自定义界面圆角显示

以下仅作为自己工作笔记。

 

 

AlertDialog自定义界面圆角显示_第1张图片

 

如上图效果:

 

1.弹出框代码

 

private AlertDialog dlg;

 

private void showAgendaialog() {

 

AlertDialog.Builder builder = new AlertDialog.Builder(this);

LayoutInflater inflater = getLayoutInflater();

 final View layout = inflater.inflate(R.layout.dialogone, null);// 获取自定义布局

    

           // 得到控件

            //TODO

 

           dlg = builder.create();

           dlg.show();

           DisplayMetrics dm = context.getResources().getDisplayMetrics();

        int displayWidth = dm.widthPixels;

        int displayHeight = dm.heightPixels;

        android.view.WindowManager.LayoutParams p = dlg.getWindow().getAttributes();  //获取对话框当前的参数值

        p.width = (int) (displayWidth * 0.88);    //宽度设置

        p.height = (int) (displayHeight * 0.70);    //高度设置

        dlg.setCanceledOnTouchOutside(true);// 设置点击屏幕Dialog不消失

        dlg.getWindow().setAttributes(p);     //设置生效

        dlg.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);   //解决点击EditText  不显示软键盘问题

        dlg.setContentView(layout);

 

}

 

 

 

 

 

 

  2.   R.layout.dialogone布局

 

    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:orientation="vertical"

    android:paddingLeft="@dimen/x10"

    android:paddingRight="@dimen/x10"

    android:paddingTop="@dimen/x10"

     android:background="@drawable/shape_bg_white"

    >

   

  

 <TextView

        android:layout_width="wrap_content"

        android:layout_height="wrap_content"

        android:text="日程标题"

        android:textSize="@dimen/x14" />

     

    <LinearLayout

        android:layout_width="match_parent"

        android:layout_height="wrap_content"

        android:orientation="vertical"

        android:layout_marginTop="@dimen/x8"

         android:background="@drawable/shape_hui_kuang"

        android:focusable="true"

           android:focusableInTouchMode="true"

        >

    <EditText

        android:id="@+id/et_rement_title"

        android:layout_width="match_parent"

        android:layout_height="@dimen/x30"

        android:background="@null"

        android:textSize="@dimen/x13"

        android:hint="请输入标题"

        android:layout_marginLeft="@dimen/x5"

        />

LinearLayout>

    <TextView

        android:layout_width="wrap_content"

        android:layout_height="wrap_content"

        android:layout_marginTop="@dimen/x8"

        android:text="日程内容"

        android:textSize="@dimen/x14" />

 <LinearLayout

        android:layout_width="match_parent"

        android:layout_height="wrap_content"

        android:orientation="vertical"

        android:layout_marginTop="@dimen/x8"

         android:background="@drawable/shape_hui_kuang"

        android:focusable="true"

     android:focusableInTouchMode="true"

        >

    <EditText

        android:id="@+id/et_rement_content"

        android:layout_width="fill_parent"

        android:layout_height="@dimen/x150"

        android:gravity="top"

        android:textSize="@dimen/x13"

           android:background="@null"

           android:hint="请输入内容!"

           android:layout_marginTop="@dimen/x10"

            android:layout_marginLeft="@dimen/x5"

            android:layout_marginRight="@dimen/x5"

         />

LinearLayout>

    <TextView

        android:layout_width="wrap_content"

        android:layout_height="wrap_content"

        android:layout_marginTop="@dimen/x8"

        android:text="选择时间"

        android:textSize="@dimen/x14" />

    <LinearLayout

        android:layout_width="match_parent"

        android:layout_height="wrap_content"

        android:layout_marginTop="@dimen/x10"

        android:orientation="horizontal" >

        <RelativeLayout

            android:id="@+id/llout_rement_choose_time"

            android:layout_width="0dp"

            android:layout_height="@dimen/x30"

            android:layout_marginRight="@dimen/x5"

            android:layout_weight="1"

          android:background="@drawable/shape_hui_kuang"

            android:gravity="center"

            android:orientation="horizontal" >

            <TextView

                android:id="@+id/rement_choose_time"

                android:layout_width="wrap_content"

                android:layout_height="wrap_content"

                android:text="请选择日期"

                android:textColor="#888888"

                android:textSize="@dimen/x13"

                android:layout_marginLeft="@dimen/x5"

                />

            <ImageView

                android:layout_width="@dimen/x13"

                android:layout_height="@dimen/x13"

                android:layout_marginLeft="8dp"

                android:layout_alignParentRight="true"

                android:layout_marginRight="@dimen/x10"

                android:src="@drawable/check_time" />

        RelativeLayout>

    LinearLayout>

  

     <View

           android:layout_width="fill_parent"

           android:layout_height="@dimen/x1"

           android:background="#F2F2F2"

           android:layout_marginTop="@dimen/x20"

           />

    <LinearLayout

           android:layout_width="fill_parent"

           android:layout_height="wrap_content"

           android:orientation="horizontal"

          

           >

           <LinearLayout

               android:id="@+id/bt_rement_cancel"

               android:layout_width="0dp"

               android:layout_height="wrap_content"

               android:layout_weight="1"

               android:gravity="center"

               android:paddingTop="@dimen/x8"

                     android:paddingBottom="@dimen/x8"

               >

               <TextView

                   android:layout_width="wrap_content"

                   android:layout_height="wrap_content"

                   android:text="取消"

                   android:textSize="@dimen/x13"

                  

                   />

           LinearLayout>

           <View

               android:layout_width="@dimen/x1"

               android:layout_height="fill_parent"

               android:background="#F2F2F2"

               />

           <LinearLayout

                android:id="@+id/bt_ament"

               android:layout_width="0dp"

               android:layout_height="fill_parent"

               android:layout_weight="1"

               android:gravity="center"

               >

               <TextView

                   android:layout_width="wrap_content"

                   android:layout_height="wrap_content"

                   android:text="修改"

                   android:textColor="#34ADF2"

                    android:textSize="@dimen/x13"

                   />

           LinearLayout>

       LinearLayout>

 

LinearLayout>

 

 

 

 

3.@drawable/shape_bg_white自定义界面背景

 

xml version="1.0" encoding="utf-8"?>

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

   

    <corners

        android:radius="@dimen/x10"

        />

   

     <solid

         android:color="@color/white"

         />

shape>

 

 

 

 

 

 

 

 

 

 

 

 

 

你可能感兴趣的:(Android笔记)