所以我在我的应用程序中创建了许多不同的对话框,并且我已经将样式应用于所有这些对话框。像这样:
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>
因此,每次调用对话框.Show()
时,它都会从屏幕底部滑入中心,当调用.Dismiss()
时,它会从屏幕中心向下滑动到底部。
现在我想制作所有这些对话框&#39;角落 我怎么能这样做?
感谢您的时间。
=====================
编辑:
我对话框的XML布局之一:
<?xml version="1.0" encoding="utf-8"?>
<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:layout_width="wrap_content">
<TextView
p1:layout_width="match_parent"
p1:layout_height="45dp"
p1:id="@+id/textCustAlertTitle"
p1:background="#ff548cac"
p1:gravity="center"
p1:textSize="18dp"
p1:textColor="@android:color/background_light"
p1:text="Text"
p1:layout_alignParentTop="true" />
<TextView
p1:layout_height="wrap_content"
p1:id="@+id/textCustAlertMesg"
p1:layout_below="@+id/textCustAlertTitle"
p1:layout_width="match_parent"
p1:background="@android:color/background_light"
p1:textSize="16dp"
p1:gravity="center"
p1:textColor="@android:color/black"
p1:layout_above="@+id/layoutCustAlertBtmBtns" />
<LinearLayout
p1:orientation="horizontal"
p1:minWidth="25px"
p1:minHeight="25px"
p1:layout_width="match_parent"
p1:layout_height="wrap_content"
p1:id="@+id/layoutCustAlertBtmBtns"
p1:weightSum="100"
p1:layout_alignWithParentIfMissing="false"
p1:layout_alignParentBottom="true"
p1:background="#ffd5d5d5">
<Button
p1:text="Cancel"
p1:id="@+id/btnCustAlertLeft"
p1:background="#ff548cac"
p1:layout_weight="50"
p1:layout_width="wrap_content"
p1:layout_height="45dp" />
<Button
p1:text="Ok"
p1:id="@+id/btnCustAlertRight"
p1:background="#ff548cac"
p1:layout_weight="50"
p1:layout_width="wrap_content"
p1:layout_height="45dp" />
</LinearLayout>
</RelativeLayout>
这就是我使用这种布局的方式:
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);
答案 0 :(得分:1)
您只需要为名为RelativeLayout
reLayoutCustomizedAlert
创建设置自定义背景
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>
setBackground的另一个选项
<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>
Solid标签用于将setBackground设置为alertDialog
我使用了相同的代码,结果如下:
将笔划设置为黑色,因此可以看到AlertDialog背景的透明度。