麻豆小视频在线观看_中文黄色一级片_久久久成人精品_成片免费观看视频大全_午夜精品久久久久久久99热浪潮_成人一区二区三区四区

首頁 > 學院 > 開發設計 > 正文

彈出對話框AlertDialog.Builder使用筆記

2019-11-09 16:31:19
字體:
來源:轉載
供稿:網友

因項目需要,需要一個彈出對話框,但對話框的布局和界面不是默認的,而是需要自己自定義的界面

(一)先實例化一個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"          android:layout_width="wrap_content"          android:layout_height="wrap_content"          android:layout_centerHorizontal="true"          android:layout_below="@+id/titleLine"          android:textSize="20sp"          android:text="當前位置"          />      <LinearLayout            android:id="@+id/contentShow"           android:layout_width="wrap_content"           android:layout_height="wrap_content"           android:layout_centerHorizontal="true"           android:layout_below="@+id/contentTitle"           android:layout_marginTop="20dp"           android:orientation="horizontal"               >      <TextView           android:id="@+id/altitued"          android:layout_width="wrap_content"          android:layout_height="wrap_content"          android:textSize="20sp"          android:text="經度:"                    />             <TextView           android:id="@+id/altituedText"          android:layout_width="wrap_content"          android:layout_height="wrap_content"          android:textSize="20sp"          android:text="NULL"          />            <TextView           android:id="@+id/longtitued"          android:layout_width="wrap_content"          android:layout_height="wrap_content"          android:layout_marginLeft="60dp"          android:textSize="20sp"          android:text="緯度:"          />             <TextView           android:id="@+id/longtituedText"          android:layout_width="wrap_content"          android:layout_height="wrap_content"          android:textSize="20sp"          android:text="NULL"          />       </LinearLayout>                   <View style="@style/horizontal_layout"          android:id="@+id/contentLine"          android:layout_below="@+id/contentShow"          android:layout_width="match_parent"          android:layout_marginTop="20dp"           />                        <LinearLayout          android:id="@+id/addressEdit"          android:layout_width="wrap_content"          android:layout_height="wrap_content"          android:layout_below="@+id/contentLine"          android:layout_centerHorizontal="true"          android:orientation="horizontal"           >        <TextView           android:id="@+id/addressName"          android:layout_width="wrap_content"          android:layout_height="wrap_content"          android:layout_gravity="center_vertical"          android:textSize="18sp"          android:text="地點名稱:"          />         <EditText           android:id="@+id/addressNameText"          android:layout_width="300dp"          android:layout_height="wrap_content"          android:textSize="18sp"             />         </LinearLayout>             </RelativeLayout>

(三)將布局轉化為View控件

View view = View.inflate(MainActivity.context, R.layout.add_address_dialog, null);

要是不明白參數可以百度一下

(四)只要將轉化的View控件加載就可以了

  addDialog.setView(view);//加載自定義布局   addDialog.show();//顯示對話框

總結:Builder易用而且還靈活,可以加載自己的布局,而且它還有兩個按鈕屬性addDialog.setPositiveButton(CharSequence text,OnClickListener listener)和addDialog.setNegativeButton(CharSequence text,OnClickListener listener),以我的理解前者是肯定按鈕,后者是否定按鈕。如果有什么不對的大家可以指正,大家相互交流學習,哈哈,,,


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: av在线免费播放 | 欧美成人免费在线视频 | 国产青草网 | 国产69精品福利视频 | 久久久久久久久日本理论电影 | 中文字幕激情视频 | 男女羞羞在线观看 | 亚洲国产美女视频 | 免费观看视频91 | 成人在线观看免费视频 | 在线看免费观看av | 色妞欧美 | 欧美亚洲一区二区三区四区 | 亚洲视屏在线 | 热久久成人 | 午夜天堂在线 | 亚洲成人入口 | 国产91精品一区二区麻豆亚洲 | 日韩精品中文字幕一区二区三区 | 日韩黄色免费观看 | 成人羞羞视频在线观看免费 | 日本网站在线播放 | 精品亚洲综合 | 国产精品久久久久久久久久三级 | 国产精品免费一区二区 | 成熟女人特级毛片www免费 | 一级空姐毛片 | 国产xxxx岁13xxxxhd | 欧美一级高清免费 | 欧美日韩电影 | 视频一区二区三区在线播放 | 精品一区二区久久久久久久网精 | 亚洲成人福利在线观看 | 国产精品久久久久久久久久10秀 | 成人免费久久网 | 91丝袜 | 黄色网址在线播放 | 91九色网 | 久久久久久久久浪潮精品 | 欧美视频网 | av日韩在线免费观看 |