Android使用Dialog風(fēng)格彈出框的Activity
在Android中經(jīng)常會(huì)遇到需要使用Dialog風(fēng)格彈出框的activity,首先我們可能會(huì)首先想到的是在XML布局文件中設(shè)置android:layout_height="wrap_content"屬性,讓activity的高度自適應(yīng),顯然這還不行,我們還需要為其DialogActivity設(shè)置自定義一個(gè)樣式
<style name="dialogstyle"> <!--設(shè)置dialog的背景--> <item name="android:windowBackground">@android:color/transparent</item> <!--設(shè)置Dialog的windowFrame框?yàn)闊o--> <item name="android:windowFrame">@null</item> <!--設(shè)置無標(biāo)題--> <item name="android:windowNoTitle">true</item> <!--是否浮現(xiàn)在activity之上--> <item name="android:windowIsFloating">true</item> <!--是否半透明--> <item name="android:windowIsTranslucent">true</item> <!--設(shè)置窗口內(nèi)容不覆蓋--> <item name="android:windowContentOverlay">@null</item> <!--設(shè)置動(dòng)畫,在這里使用讓它繼承系統(tǒng)的Animation.Dialog--> <item name="android:windowAnimationStyle">@android:style/Animation.Dialog</item> <!--背景是否模糊顯示--> <item name="android:backgroundDimEnabled">true</item> </style>
然后在AndroidManifest.xml中設(shè)置DialogActivity的樣式為我們自定義的dialogstyle
如下是布局的代碼
<?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="wrap_content" android:background="@color/white" android:orientation="vertical"> <LinearLayout android:layout_width="match_parent" android:layout_height="65dp" android:orientation="horizontal" android:paddingLeft="@dimen/acitvity_margin" android:paddingRight="@dimen/acitvity_margin"> <LinearLayout android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" android:orientation="horizontal"> <TextView android:layout_width="wrap_content" android:layout_height="match_parent" android:gravity="center" android:text="上班時(shí)間:" android:textColor="@color/grey" android:textSize="@dimen/size_text_medium" /> <Button android:id="@+id/tv_signin_time" android:layout_width="wrap_content" android:layout_height="match_parent" android:background="@color/white" android:gravity="center" android:text="9:00" android:textColor="@color/grey" android:textSize="@dimen/size_text_medium" /> </LinearLayout> <LinearLayout android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" android:orientation="horizontal"> <TextView android:layout_width="wrap_content" android:layout_height="match_parent" android:gravity="center" android:text="下班時(shí)間:" android:textColor="@color/grey" android:textSize="@dimen/size_text_medium" /> <Button android:id="@+id/tv_signout_time" android:layout_width="wrap_content" android:layout_height="match_parent" android:background="@color/white" android:gravity="center" android:text="18:00" android:textColor="@color/grey" android:textSize="@dimen/size_text_medium" /> </LinearLayout> </LinearLayout> <RelativeLayout android:layout_width="match_parent" android:layout_height="65dp" android:paddingLeft="@dimen/acitvity_margin" android:paddingRight="@dimen/acitvity_margin"> <TextView android:layout_width="wrap_content" android:layout_height="match_parent" android:layout_alignParentLeft="true" android:gravity="center" android:text="公司位置:" android:textColor="@color/grey" android:textSize="@dimen/size_text_medium" /> <EditText android:id="@+id/et_address" android:layout_width="wrap_content" android:layout_height="match_parent" android:layout_marginLeft="2dp" android:layout_toRightOf="@+id/tv_address" android:background="@color/white" android:hint="請(qǐng)輸入公司位置" android:singleLine="true" android:textSize="@dimen/size_text_small" /> <TextView android:id="@+id/tv_location" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentRight="true" android:layout_centerInParent="true" android:gravity="center" android:padding="5dp" android:text="重新定位" android:textColor="@color/blue" android:textSize="@dimen/size_text_medium" /> </RelativeLayout> <RelativeLayout android:layout_width="match_parent" android:layout_height="65dp" android:paddingLeft="@dimen/acitvity_margin" android:paddingRight="@dimen/acitvity_margin"> <TextView android:layout_width="wrap_content" android:layout_height="match_parent" android:layout_alignParentLeft="true" android:gravity="center" android:text="設(shè)置管理員:" android:textColor="@color/grey" android:textSize="@dimen/size_text_medium" /> <ImageView android:layout_width="wrap_content" android:layout_height="match_parent" android:layout_alignParentRight="true" android:gravity="center" android:src="@mipmap/icon_toright" /> </RelativeLayout> </LinearLayout>
接下來我們?cè)倏匆幌滦Ч麍D是不是我們想要的呢
源碼下載:http://xiazai.jb51.net/201609/yuanma/DialogActivity(jb51.net).rar
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- Android 多種簡(jiǎn)單的彈出框樣式設(shè)置代碼
- Android實(shí)現(xiàn)可輸入數(shù)據(jù)的彈出框
- react-native 封裝選擇彈出框示例(試用ios&android)
- Android中自定義PopupWindow實(shí)現(xiàn)彈出框并帶有動(dòng)畫效果
- Android 仿微信朋友圈點(diǎn)贊和評(píng)論彈出框功能
- android自定義彈出框樣式的實(shí)現(xiàn)方法
- 高仿IOS的Android彈出框
- Android仿微信進(jìn)度彈出框的實(shí)現(xiàn)方法
- Android編程實(shí)現(xiàn)仿QQ發(fā)表說說,上傳照片及彈出框效果【附demo源碼下載】
- Android自定義彈出框的方法
相關(guān)文章
Android使用CountDownTimer類實(shí)現(xiàn)倒計(jì)時(shí)鬧鐘
這篇文章主要為大家詳細(xì)介紹了Android使用CountDownTimer類實(shí)現(xiàn)倒計(jì)時(shí)鬧鐘,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-01-01Flutter 插件url_launcher簡(jiǎn)介
最近項(xiàng)目需求是打開一個(gè)連接跳轉(zhuǎn)到安卓或蘋果默認(rèn)的瀏覽器。雖然開始一個(gè)簡(jiǎn)單的要求,其中的一個(gè)細(xì)節(jié)就是執(zhí)行打開網(wǎng)頁這一操作后,不能看上去像在應(yīng)用內(nèi)部打開,看上去要在應(yīng)用外部打開,今天小編給大家介紹Flutter 插件url_launcher的相關(guān)知識(shí),感興趣的朋友一起看看吧2020-04-04android TextView實(shí)現(xiàn)跑馬燈效果
這篇文章主要為大家詳細(xì)介紹了android TextView實(shí)現(xiàn)跑馬燈效果,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-06-06android byte[] 和short[]轉(zhuǎn)換的方法代碼
這篇文章主要介紹了android byte[] 和short[]轉(zhuǎn)換的方法代碼,有需要的朋友可以參考一下2014-01-01Android自定義View實(shí)現(xiàn)箭頭沿圓轉(zhuǎn)動(dòng)實(shí)例代碼
這篇文章主要介紹了Android自定義View實(shí)現(xiàn)箭頭沿圓轉(zhuǎn)動(dòng)實(shí)例代碼,需要的朋友可以參考下2017-09-09Flutter實(shí)現(xiàn)底部導(dǎo)航欄效果
這篇文章主要為大家詳細(xì)介紹了Flutter實(shí)現(xiàn)底部導(dǎo)航欄效果,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-08-08