Android 自定义AlertDialog 并且4个角为圆角
16lz
2021-01-23
//自定义AlertDialogLayoutInflater inflater = getLayoutInflater();View view1 = inflater.inflate(R.layout.dialog_activity, null);ImageView ivguanbi = view1.findViewById(R.id.iv_guanbi);TextView wjmm = view1.findViewById(R.id.tv_wjmm);EditText namephone = view1.findViewById(R.id.et_namephone);EditText newpassword = view1.findViewById(R.id.et_newpassword);EditText yanzhenma = view1.findViewById(R.id.yanzhenma);Button cxhqyzm = view1.findViewById(R.id.btn_nxhqyzm);//给textview字体加粗TextPaint paint = wjmm.getPaint();paint.setFakeBoldText(true);显示AlertDialogAlertDialog dialog = new AlertDialog.Builder(this) .setView(view1) .show();//给AlertDialog设置4个圆角dialog.getWindow().setBackgroundDrawableResource(R.drawable.dialogbg);
设置dialogbg或者说设置圆角并填充背景色或者说设置shape<?xml version="1.0" encoding="utf-8"?><shape xmlns:android="http://schemas.android.com/apk/res/android"> <corners android:radius="30dp" /> <solid android:color="@color/colorWhite" />shape>AlertDialog自定义xml布局代码如下:
<?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/dialogbg" android:orientation="vertical" android:padding="30dp"> <ImageView android:id="@+id/iv_guanbi" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="right" android:src="@mipmap/btn_close" /> <TextView android:id="@+id/tv_wjmm" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginBottom="20dp" android:gravity="center" android:text="忘记密码" android:textColor="@color/colorBlack" android:textSize="25sp" /> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center" android:text="用户名:" android:textSize="12sp" /> <EditText android:id="@+id/et_namephone" android:layout_width="match_parent" android:layout_height="30dp" android:layout_marginBottom="10dp" android:layout_marginLeft="10dp" android:layout_marginRight="10dp" android:background="@drawable/list_insert" android:gravity="center" android:hint="注册所用手机号" /> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center" android:text="新密码:" android:textSize="12sp" /> <EditText android:id="@+id/et_newpassword" android:layout_width="match_parent" android:layout_height="30dp" android:layout_marginBottom="10dp" android:layout_marginLeft="10dp" android:layout_marginRight="10dp" android:background="@drawable/list_insert" android:gravity="center" android:inputType="textPassword" /> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center" android:text="验证码:" android:textSize="12sp" /> <EditText android:id="@+id/yanzhenma" android:layout_width="match_parent" android:layout_height="30dp" android:layout_marginBottom="20dp" android:layout_marginLeft="10dp" android:layout_marginRight="10dp" android:background="@drawable/list_insert" android:gravity="center" /> <Button android:id="@+id/btn_nxhqyzm" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@drawable/bg" android:text="从新或取验证码" android:textColor="@color/colorWhite" />LinearLayout>
更多相关文章
- 在Android studio中无法实时显示布局的问题
- android studio 引入另一个XML文件的布局控件
- android 我的功能模块模板布局之一
- 解决TabLayout+viewpager 滑动切换时 布局文件不是从头显示
- Android控件布局属性大全
- Android之LinearLayout(线性布局)
- Android 布局加载源代码分析
- Android UI布局