2012-04-09 52 views
9

我需要创建一个应该看起来像一个圆角对话框的活动。如何获得圆形对话框主题的活动

对于这个要求,我将

android:theme="@android:style/Theme.Dialog" 

现在我的行​​为看起来像一个对话框,但我需要它的边角为圆弧形。

然后我创建了xml属性,并将此drawable设置为我的活动主题,但现在我的活动看起来不像对话框。

请建议我可以做些什么,以便我的活动看起来像带圆角的对话框。

回答

31

你可以让你自己的theme有圆角。首先,您需要一个drawableActivity背景:

<?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> 

下使自己的主题,它扩展了父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> 

这将是一个在res/values文件夹命名为styles.xml文件。使用这个主题在Android清单为Activity你想要的:

//... 
<activity 
      android:name=".ActivityName" 
      android:label="@string/app_name" 
      android:theme="@style/ThemeWithCorners" > 
//... 
+0

请亲爱的你的答案可以应用于冰淇淋sandwish alertdialog,我尝试但它不工作,不能得到圆角,谢谢 – 2012-09-28 22:35:15

+0

好的答案谢谢 – 2014-01-18 16:40:25

+0

感谢您的提示使用主题。只要将drawable设置为背景,不会使角位透明。 – 2015-09-26 22:49:07

0

首先,创建一个圆角形状绘制像这样:

dialogbg.xml:

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

然后,转到你的活动布局xml文件,并改变它的Android:backgorund属性像所以

<RelativeLayout 
    android:layout_width="..." 
    android:layout_height="..." 
    android:background="@drawable/dialogbg"> 
    <!--views here...--> 
</RelativeLayout> 
+2

Saarraz,感谢您的帮助,但我尝试了上述解决方案,其修改布局的形状,但不是实际的活动。 – brig 2012-04-09 11:03:37

相关问题