HTML怎么自定義dialog背景?這個(gè)問題可能是我們?nèi)粘W(xué)習(xí)或工作經(jīng)常見到的。希望通過這個(gè)問題能讓你收獲頗深。下面是小編給大家?guī)淼膮⒖純?nèi)容,讓我們一起來看看吧!
現(xiàn)在我們先來實(shí)現(xiàn)文章的第一個(gè)問題,HTML如何自定義dialog標(biāo)簽的背景的:
現(xiàn)在很多App的提示對話框都非常有個(gè)性,然而你還用系統(tǒng)的對話框樣式,是不是覺得很落后呢,今天我就給大家講講怎樣自定義自己的Dialog,學(xué)會(huì)了之后,你就會(huì)根據(jù)自家app的主題,設(shè)計(jì)出相應(yīng)的Dialog的風(fēng)格。
好了接下來我就以一個(gè)簡單風(fēng)格的自定義Dialog來講講自定義dialog的一般步驟和原理。
第一步: 給Dialog設(shè)置一個(gè)風(fēng)格主題(基本都是用這個(gè)主題)無邊框全透明背景:
<!--自定義dialog背景全透明無邊框theme --> <style name="MyDialog" parent="android:style/Theme.Dialog"> <!--背景顏色及和透明程度--> <item name="android:windowBackground">@android:color/transparent</item> </style>
dialog的自定義背景框如下:
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android"> <solid android:color="#ffffff" /> <stroke android:width="0.8dp" android:color="#ffffff" /> <!-- 圓角 --> <corners android:radius="6dp" /> </shape>
以上就是在APP中自定義dialog背景的簡單過程了,要想了解的更多,請上創(chuàng)新互聯(lián)建站了解更多知識(shí)。
現(xiàn)在我們說說如何自定義dialog:
東西很多,慢慢看
<style name="MyDialog" parent="android:style/Theme.Dialog"> <!--背景顏色及和透明程度--> <item name="android:windowBackground">@android:color/transparent</item> <!--是否去除標(biāo)題 --> <item name="android:windowNoTitle">true</item> <!--是否去除邊框--> <item name="android:windowFrame">@null</item> <!--是否浮現(xiàn)在activity之上--> <item name="android:windowIsFloating">true</item> <!--是否模糊--> <item name="android:backgroundDimEnabled">false</item> </style>
第二步:給自定的Dialog設(shè)置自定義的 xml界面,我這里只是示范,你可以使用單選,多選,3個(gè)按鈕,4個(gè)按鈕等等,格式各樣的自定義XML,我這里就定義了 標(biāo)題title,信息message,還有一個(gè)確定按鈕和取消按鈕,如下:
<?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="#11ffffff"> <LinearLayout android:layout_width="260dp" android:layout_height="wrap_content" android:layout_centerInParent="true" android:background="@drawable/free_dialog_bg" android:orientation="vertical"> <TextView android:id="@+id/title" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:layout_margin="15dp" android:gravity="center" android:text="消息提示" android:textColor="#38ADFF" android:textSize="16sp" /> <TextView android:id="@+id/message" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="20dp" android:layout_marginRight="20dp" android:text="提示消息" /> <View android:layout_width="match_parent" android:layout_height="1px" android:layout_marginTop="15dp" android:background="#E4E4E4" /> <LinearLayout android:layout_width="match_parent" android:layout_height="40dp" android:orientation="horizontal"> <Button android:id="@+id/no" android:layout_width="0dp" android:layout_height="match_parent" android:layout_marginLeft="10dp" android:layout_weight="1" android:background="@null" android:gravity="center" android:singleLine="true" android:text="No" android:textColor="#7D7D7D" android:textSize="16sp" /> <View android:layout_width="1px" android:layout_height="match_parent" android:background="#E4E4E4" /> <Button android:id="@+id/yes" android:layout_width="0dp" android:layout_height="match_parent" android:layout_marginRight="10dp" android:layout_weight="1" android:background="@null" android:gravity="center" android:singleLine="true" android:text="Yes" android:textColor="#38ADFF" android:textSize="16sp" /> </LinearLayout> </LinearLayout> </RelativeLayout>
dialog的自定義背景框如下:
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android"> <solid android:color="#ffffff" /> <stroke android:width="0.8dp" android:color="#ffffff" /> <!-- 圓角 --> <corners android:radius="6dp" /> </shape>
這就完成了雖然很長,但是學(xué)習(xí)是個(gè)很慢的過程。一點(diǎn)一點(diǎn)的來吧
感謝各位的閱讀!看完上述內(nèi)容,你們對HTML怎么自定義dialog背景大概了解了嗎?希望文章內(nèi)容對大家有所幫助。如果想了解更多相關(guān)文章內(nèi)容,歡迎關(guān)注創(chuàng)新互聯(lián)網(wǎng)站制作公司行業(yè)資訊頻道。
網(wǎng)頁題目:HTML怎么自定義dialog背景-創(chuàng)新互聯(lián)
地址分享:http://www.rwnh.cn/article28/dggscp.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供App開發(fā)、搜索引擎優(yōu)化、品牌網(wǎng)站制作、微信小程序、全網(wǎng)營銷推廣、網(wǎng)站內(nèi)鏈
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容