Android的PopupWindow是個很有用的widget,利用它可以實現(xiàn)懸浮窗體的效果,比如實現(xiàn)一個懸浮的菜單,最常見的應用就是在視頻播放界面里,做一個工具欄,用來控制播放進度。本文利用PopupWindow來實現(xiàn)一個通用的Dailog,類似Android系統(tǒng)的AlertDailog,從中學習和掌握有關PopupWindow和Dailog的使用和實現(xiàn)細節(jié)。
成都創(chuàng)新互聯(lián)公司主營疏勒網(wǎng)站建設的網(wǎng)絡公司,主營網(wǎng)站建設方案,app軟件開發(fā),疏勒h5微信小程序開發(fā)搭建,疏勒網(wǎng)站營銷推廣歡迎疏勒等地區(qū)企業(yè)咨詢界面效果如圖所示,點擊 Click 按鈕后,彈出對話框提示。
(1). CustomDailog的布局
首先定義 CustDailog的布局文件,由系統(tǒng)的AlertDailog可以知道,一個對話框包含了三個要素,一個是Title,即標題,一個是Message,即主體內(nèi)容,還有一個是Button,即確定和取消的按鈕,用來與用戶交互。因此,布局設計如下:
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="vertical" android:background="@drawable/shape_bg" android:layout_margin="10dp"> <TextView android:id="@+id/CustomDlgTitle" android:layout_width="match_parent" android:layout_height="wrap_content" android:textStyle="bold" android:textSize="20sp" android:layout_margin="10dp" android:gravity="center"/> <View android:layout_width="match_parent" android:layout_height="1dp" android:background="@android:color/darker_gray"/> <LinearLayout android:id="@+id/CustomDlgContentView" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" android:layout_margin="5dp" /> <TextView android:id="@+id/CustomDlgContentText" android:layout_width="match_parent" android:layout_height="wrap_content" android:textSize="15sp" android:layout_margin="5dp" android:paddingLeft="5sp"/> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" android:layout_margin="5dp" > <Button android:id="@+id/CustomDlgButtonOK" android:layout_width="0dp" android:layout_weight="0.5" android:layout_height="wrap_content" android:visibility="gone"/> <Button android:id="@+id/CustomDlgButtonCancel" android:layout_width="0dp" android:layout_weight="0.5" android:layout_height="wrap_content" android:visibility="gone"/> </LinearLayout> </LinearLayout>
本文名稱:Android用PopupWindow實現(xiàn)自定義Dailog-創(chuàng)新互聯(lián)
當前URL:http://aaarwkj.com/article18/ppjdp.html
成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供建站公司、外貿(mào)網(wǎng)站建設、定制開發(fā)、網(wǎng)站排名、全網(wǎng)營銷推廣、品牌網(wǎng)站建設
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容