xamarin 通过样式设置AlertDialog视图插图

2ledvvac  于 2022-12-16  发布在  其他
关注(0)|答案(1)|浏览(115)

我使用Acr.UserDialogs从Xamarin Shared/PCL项目创建跨平台对话框。(在Android中)是一个AlertDialog,其视图设置为EditText。不幸的是,视图/EditText没有边距/填充,这导致它到达对话框的外部左右界限-这看起来相当丑陋。由于它是一个库,我无法更改EditText或AlertDialog的确切创建方式(而不是自己在GitHub上编辑库代码,但如果可能的话,我现在尽量避免这种方式)。该库支持的是将AndroidStyleId传递到其使用的调用中的可能性,而不是默认的Android AlertDialog样式(new AlertDialog.Builder(activity, passedAndroidStyleId))。
现在,我的想法是创建一个样式,定义AlertDialog视图的自定义边距/填充/插入,如下所示,并将其传递进来。

<style name="CustomPromptDialog" parent="ThemeOverlay.AppCompat.Dialog.Alert">
    <item name="viewInset">10dp</item>
</style>

问题是我找不到任何列出哪些“属性”可以在样式中设置或如何命名的资源,所以我唯一的想法是在这里询问:有没有什么方法可以达到我想做的事情?如果有,怎么做?

xienkqul

xienkqul1#

您可以像这样设置样式来改变Alertdialog的形式。这是全局设置的方法。

<style name="MainTheme" parent="MainTheme.Base">
        <item name="android:datePickerDialogTheme">@style/Theme.picker</item>
        <item name="alertDialogTheme">@style/Theme.alert</item>
</style>
    
    <style name="Theme.alert" parent="ThemeOverlay.AppCompat.Dialog.Alert">
         <item name="colorAccent">#FFC107</item>
    <!-- Used for the title and text -->
    <item name="android:textColorPrimary">#FFC107</item>
    <!-- Used for the background -->
    <item name="android:background">#4CAF50</item>
    <item name="viewInset">10dp</item>

相关问题