带圆角的Android对话主题

带圆角的Android对话主题,android,xml,xamarin,Android,Xml,Xamarin,因此,我在我的应用程序中创建了许多不同的对话框,并对所有对话框应用了一种样式。像这样: custAlertDialog = new Dialog (context, Resource.Style.customizedAlertSlideUpAndDown); 我就是这样做的customizedAlertSlideUpAndDown: <style name="customizedAlertSlideUpAndDown" parent="@android:style/Theme.Dialo

因此,我在我的应用程序中创建了许多不同的对话框,并对所有对话框应用了一种样式。像这样:

custAlertDialog = new Dialog (context, Resource.Style.customizedAlertSlideUpAndDown);
我就是这样做的
customizedAlertSlideUpAndDown

<style name="customizedAlertSlideUpAndDown" parent="@android:style/Theme.Dialog">
    <item name="android:windowAnimationStyle">@style/slideUpAndDown</item>
    <item name="android:windowBackground">@android:color/transparent</item>
</style>

<style name="slideUpAndDown">
    <item name="android:windowEnterAnimation">@anim/anim_popup_slideup</item>
    <item name="android:windowExitAnimation">@anim/anim_popup_slidedown</item>
</style>
这就是我使用这个布局的方式:

var inflater = Application.Context.GetSystemService (Context.LayoutInflaterService) as LayoutInflater;

// creating view from the layout
var customizedAlert = inflater.Inflate (Resource.Layout.CustomizedAlert, null);

// creating new dialog
custAlertDialog = new Dialog (context, Resource.Style.customizedAlertSlideUpAndDown);

// setting the view as my entire dialog
custAlertDialog.SetContentView (customizedAlert);

您只需为您的父级
RelativeLayout
named
relayCustomedAlert

rouund_corner_bg.xml

<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <stroke android:width="1dp" android:color="@android:color/transparent" />
    <solid android:color="@android:color/transparent" />
    <corners 
        android:bottomRightRadius="4dp" 
        android:bottomLeftRadius="4dp" 
        android:topLeftRadius="4dp" 
        android:topRightRadius="4dp"/>  
</shape>

然后将此背景设置为

<style name="customizedAlertSlideUpAndDown" parent="@android:style/Theme.Dialog">
    <item name="android:windowAnimationStyle">@style/slideUpAndDown</item>
    <item name="android:windowBackground">@drawable/rouund_corner_bg.xml</item>
</style>

@样式/滑动展开
@可绘制的/rouund_corner_bg.xml
否则另一个选择就是退步

<RelativeLayout xmlns:p1="http://schemas.android.com/apk/res/android"
    p1:minWidth="25px"
    p1:minHeight="25px"
    p1:layout_height="223dp"
    p1:id="@+id/reLayoutCustomizedAlert"
    p1:background="@drawable/rouund_corner_bg"
    p1:layout_width="wrap_content">
</RelativeLayout>

标记用于将背景设置为alertDialog

我使用了相同的代码,结果如下:

将笔划设置为黑色,以便可以看到AlertDialog背景的透明度


为对话框使用自定义视图或xml?对话框在我的MainActivity上。我已经用XML创建了一个布局,该布局被设置为对话框的视图。我已经用对话框的XML布局代码之一更新了我的原始帖子。即使有一种方法可以从这个XML代码中实现,我还是想知道是否可以通过样式来实现。这样,我就不必回去为所有不同的对话框更改它。实际上,这不起作用。
转角
笔划
是否必须应用于对话框本身?将此应用于
RelativeLayout
没有任何作用。因为您已将
xmlns:android
更改为
xmlns:p1
,所以每个android属性仅在
p1:
之后可用,而不是
android:
检查更新的代码。我也尝试了更新的答案。它不起作用。我还从对话框主题中删除了
android:windowBackground
,只是为了测试它,现在我可以在我的相对布局周围看到对话框的背景。此
rouund\u corner\u bg.xml
对对话框本身没有影响。有没有办法改变对话框的角点而不是相对位置呢?所以我解决了这个问题。你的解决方案不是问题。如果再次查看我的XML布局,第一个
TextView
textCustAlertTitle覆盖了对话框的各个角落。因为那是蓝色的,对话角在下面。是否有剪辑子视图的方法?否则,我必须手动为这些组件圆角。
<RelativeLayout xmlns:p1="http://schemas.android.com/apk/res/android"
    p1:minWidth="25px"
    p1:minHeight="25px"
    p1:layout_height="223dp"
    p1:id="@+id/reLayoutCustomizedAlert"
    p1:background="@drawable/rouund_corner_bg"
    p1:layout_width="wrap_content">
</RelativeLayout>