how to get rounded dialog theme for activity

前端 未结 2 785
星月不相逢
星月不相逢 2021-01-02 01:43

I need to create a activity which should look like as a dialog box with a rounded corners.

For this requirement I set

 android:theme=\"@android:sty         


        
相关标签:
2条回答
  • 2021-01-02 02:02

    First, create a rounded corner shape drawable like so:

    dialogbg.xml:

    <?xml version="1.0" encoding="utf-8"?>
    <shape xmlns:android="http://schemas.android.com/apk/res/android">
        <corners android:radius="15dp" />
    </shape>
    

    Then, go to the layout xml file for your activity, and change it's android:backgorund attribute like so

    <RelativeLayout 
        android:layout_width="..." 
        android:layout_height="..." 
        android:background="@drawable/dialogbg">
        <!--views here...-->
    </RelativeLayout>
    
    0 讨论(0)
  • 2021-01-02 02:03

    You could make your own theme that has rounded corners. First you'll need a drawable for the Activity background:

    <?xml version="1.0" encoding="utf-8"?>
    <shape xmlns:android="http://schemas.android.com/apk/res/android" >
    
        <corners android:radius="15dp" />
    
        <solid android:color="#565656" />
    
        <stroke
            android:width="3dp"
            android:color="#ffffff" />
    
        <padding
            android:bottom="6dp"
            android:left="6dp"
            android:right="6dp"
            android:top="3dp" />
    
    </shape>
    

    Next make your own theme that extends the parent Theme.Dialog:

    <?xml version="1.0" encoding="utf-8"?>
    <resources>
    
        <style name="ThemeWithCorners" parent="android:Theme.Dialog">
            <item name="android:windowBackground">@drawable/another_test_drawable</item>
        </style>
    
    
    </resources>
    

    This will be in a file named styles.xml in the res/values folder. Use this theme in the android manifest for the Activity you want:

    //...
    <activity
                android:name=".ActivityName"
                android:label="@string/app_name"
                android:theme="@style/ThemeWithCorners" >
    //...
    
    0 讨论(0)
提交回复
热议问题