android4步搞定自訂dialog

來源:互聯網
上載者:User

標籤:android   style   http   io   ar   color   sp   java   檔案   

第一步,drawable建立一個圓角的背景xml dialog.xml

<?xml version="1.0" encoding="utf-8"?><!-- 使用者註冊紅色按鈕 --><shape xmlns:android="http://schemas.android.com/apk/res/android"    android:shape="rectangle"><!-- android:shape="" 表示是圓角矩形還是橢圓等等 -->    <solid android:color="背景顏色" />    <!-- 背景顏色 -->    <!-- padding 表示內部空間距離背景圖片內部邊距 的距離 -->    <padding android:top="15dp" android:bottom="15dp" />    <stroke        android:width="0dp"        android:color="#ffffff" />    <!-- 圖片邊框屬性 -->    <corners android:radius="5dp" />    <!-- 圓角的程度 -->    <gradient        android:angle="45"        android:centerColor="漸層中間的顏色"        android:centerX="0.5"        android:centerY="0.5"        android:endColor="漸層結束的顏色"        android:startColor="漸層開始的顏色"        android:type="linear" /></shape>
第二步:在style.xml下建立自訂style

 <style name="my_dialog" parent="@android:style/Theme.Dialog">        <item name="android:colorBackgroundCacheHint">@null</item>        <item name="android:windowNoTitle">true</item>        <item name="android:windowFrame">@null</item><!--邊框-->        <item name="android:windowIsFloating">true</item><!--是否浮現在activity之上-->        <item name="android:windowIsTranslucent">false</item><!--半透明-->        <item name="android:background">@drawable/dialog</item><!--dialog背景樣式-->        <item name="android:windowBackground">@android:color/transparent</item><!-- 背景透明 -->        <item name="android:backgroundDimEnabled">true</item><!--模糊-->    </style>


第三步:

建立一個自訂的layout檔案my_layout.xml,內容隨你喜歡,這裡就不寫了

第四步:

 Dialog dialog = new Dialog(context, R.style.my_dialog);
 dialog.setContentView(R.layout.my_layout.xml);
搞定


android4步搞定自訂dialog

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.