Android 將Activity以對話方塊(Dialog)形式顯示

來源:互聯網
上載者:User

標籤:android   style   http   io   color   ar   os   使用   sp   

1、將MainActivity以對話方塊的形式顯示,首先在AndroidManifest.xml 檔案中,申明 activity 的主題使用自訂對話方塊樣式。

<activity

android:name=".MainActivity" 

android:label="@string/activity_custom_dialog" 

android:theme = "@style/Theme.CustomDialog" >                < intent-filter >                    < action android:name = "android.intent.action.MAIN" />                    < category android:name = "android.intent.category.SAMPLE_CODE" />                </ intent-filter >   </ activity >   2、res/values/styles.xml 樣式檔案中定義一個對話方塊主題樣式,這裡繼承了 android:style/Theme.Dialog 主題,       並且視窗樣式 android:windowBackground 引用了 @drawable/filled_box       < style name = "Theme.CustomDialog" parent = "android:style/Theme.Dialog" >        < item name = "android:windowBackground" >@drawable/filled_box</ item >   </ style >   3、res/drawable/filled_box.xml 定義了 Shape 類型的 drawable(抽象的可畫地區),最終是通過這個來實現新對話方塊的樣式。   < shape xmlns:android = "http://schemas.android.com/apk/res/android" >        < solid android:color = "#f0600000" />        < stroke android:width = "3dp" color = "#ffff8080" />        < corners android:radius = "3dp" />        < padding android:left = "10dp" android:top = "10dp"           android:right = "10dp" android:bottom = "10dp" />   </ shape >

Android 將Activity以對話方塊(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.