簡體   English   中英

通過樣式設置 AlertDialog View Inset

[英]Set AlertDialog View Inset via style

我使用 Acr.UserDialogs 從 Xamarin Shared/PCL 項目創建跨平台對話框。 Acr.UserDialogs 包含一種創建提示的方法,該提示(在 Android 中)是一個 AlertDialog,其 View 設置為 EditText。 不幸的是,View/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>

問題是我找不到任何資源列出可以在樣式中設置哪些“屬性”或它們的命名方式,所以我唯一的想法是在這里問:有什么方法可以實現我想要做的事情嗎? 如果是,怎么辦?

您可以像這樣設置樣式來更改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>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM