AlertDialog自定义界面圆角显示

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

 

 

 

如上图效果:

 

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>

 

 

 

 

 

 

 

 

 

 

 

 

 

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值