通过样式更改Android Dialog按钮文本大小

Luk*_*man 11 android android-layout android-theme android-dialog android-styles

我试图通过样式扩大我的所有应用程序对话框按钮上的文本大小.以下代码将更改按钮背景颜色甚至文本大小写,但由于某种原因,textSize项目不符合:

<style name="MyAppTheme" parent="@android:style/Theme.Holo">
    <item name="android:dialogTheme">@style/MyApp.Dialog</item>
    <item name="android:alertDialogTheme">@style/MyApp.Dialog.Alert</item>
</style>

<style name="MyApp.Dialog" parent="@android:style/Theme.Holo.Dialog">
    <item name="android:borderlessButtonStyle">@style/MyApp.BorderlessButton</item>
</style>

<style name="MyApp.Dialog.Alert" parent="@style/MyApp.Dialog">
    <item name="android:windowBackground">@android:color/transparent</item>
</style>

<style name="MyApp.BorderlessButton" parent="@android:style/Widget.Holo.Button.Borderless">
    <item name="android:textSize">50sp</item>
    <item name="android:textAllCaps">true</item>
    <item name="android:background">#800</item>
</style>
Run Code Online (Sandbox Code Playgroud)

带有背景颜色和textAllCaps但没有文字大小的对话框按钮

为什么没有读取textSize?我需要做些什么来扩大它?

Vik*_*ram 5

您没有在此处指定正确的属性:

<style name="MyApp.Dialog" parent="@android:style/Theme.Holo.Dialog">
====>    <item name="android:borderlessButtonStyle">@style/MyApp.BorderlessButton</item>
</style>
Run Code Online (Sandbox Code Playgroud)

您需要使用的属性是:

android:buttonStyle
Run Code Online (Sandbox Code Playgroud)

我建议进行以下更改:

<style name="MyApp.Dialog" parent="@android:style/Theme.Holo.Dialog">
    <item name="android:buttonStyle">@style/MyApp.BorderlessButton</item>
</style>
Run Code Online (Sandbox Code Playgroud)

为什么:

borderlessButtonStyle是一种方便定义的风格.但它目前没有连接到任何默认属性 - 在这种情况下,buttonStyle.你仍然需要分配它.

我无法弄清楚为什么backgroundtextAllCaps属性生效.发布对话框/警告对话框的xml可能会有所帮助.另外,你如何定义字符串 - "我同意"或"我同意"?


小智 -2

尝试一下这种风格:

<style name="MyApp.BorderlessButton" parent="@android:style/Widget.Holo.Button.Borderless">
   <item name="android:textSize">50sp</item>
   <item name="android:textAllCaps">true</item>
   <item name="android:background">#800</item>
</style>
Run Code Online (Sandbox Code Playgroud)