弹出对话框AlertDialog.Builder使用笔记

本文介绍了如何在Android中使用AlertDialog.Builder自定义对话框布局,包括实例化Builder对象、创建XML布局、加载自定义布局到对话框以及设置按钮操作。

因项目需要,需要一个弹出对话框,但对话框的布局和界面不是默认的,而是需要自己自定义的界面


(一)先实例化一个Builder对象

AlertDialog.Builder addDialog = new AlertDialog.Builder(Context);


参数:Context是上下文


(二)自定义布局add_address_dialog.xml,这个布局就是你自己弹出对话框的布局,我这里就要我的

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#ffffff"
     >
    
    <TextView 
        android:id="@+id/title"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="26sp"
        android:text="新增地址"
        />
    
      <View style="@style/horizontal_layout"
          android:id="@+id/titleLine"
          android:layout_below="@+id/title"
          android:layout_width="match_parent"
           /> 
           
      
      <TextView 
          android:id="@+id/contentTitle"
 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值