Подтвердить что ты не робот

Изменение размера текста кнопки диалогового окна Android с помощью стилей

Я пытаюсь увеличить размер текста на всех моих диалоговых окнах приложений через стили. Следующий код изменит цвет фона кнопок и даже текстовый футляр, но по какой-либо причине элемент 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>

Dialog button with background colour and textAllCaps but no text size

Почему текст не читается? Что мне нужно сделать, чтобы сделать его больше?

4b9b3361

Ответ 1

Здесь вы не назначаете правильный атрибут:

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

Атрибут, который вам нужно использовать:

android:buttonStyle

Я предлагаю следующее изменение:

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

Почему:

borderlessButtonStyle - это удобный стиль. Но в настоящее время он не подключен ни к одному из атрибутов по умолчанию - в этом случае buttonStyle. Вам все равно нужно назначить его.

Я не могу понять, почему атрибуты background и textAllCaps вступают в силу. Проведение диалога диалога/диалога диалогов xml может помочь. Кроме того, как вы определили строку - "Я согласен" или "Я СОГЛАСЕН"?

Ответ 2

Кнопки a AlertDialog используют android:buttonBarButtonStyle в Холо. Переопределите этот атрибут в своих темах/стилях и установите android:minHeight="0dp" для обертывания содержимого или, конечно же, ваш провайдер может создать собственную высоту.

Исправление: я неправильно прочитал заголовок. Вы, конечно, можете установить android:textSize="32sp" в том же стиле, чтобы изменить размер текста.

Вот макет для него из рамки:

<LinearLayout android:id="@+id/buttonPanel"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:minHeight="@dimen/alert_dialog_button_bar_height"
    android:orientation="vertical"
    android:divider="?android:attr/dividerHorizontal"
    android:showDividers="beginning"
    android:dividerPadding="0dip">
    <LinearLayout
        style="?android:attr/buttonBarStyle"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:layoutDirection="locale"
        android:measureWithLargestChild="true">
        <Button android:id="@+id/button2"
            android:layout_width="wrap_content"
            android:layout_gravity="start"
            android:layout_weight="1"
            android:maxLines="2"
            style="?android:attr/buttonBarButtonStyle"
            android:textSize="14sp"
            android:minHeight="@dimen/alert_dialog_button_bar_height"
            android:layout_height="wrap_content" />
        <Button android:id="@+id/button3"
            android:layout_width="wrap_content"
            android:layout_gravity="center_horizontal"
            android:layout_weight="1"
            android:maxLines="2"
            style="?android:attr/buttonBarButtonStyle"
            android:textSize="14sp"
            android:minHeight="@dimen/alert_dialog_button_bar_height"
            android:layout_height="wrap_content" />
        <Button android:id="@+id/button1"
            android:layout_width="wrap_content"
            android:layout_gravity="end"
            android:layout_weight="1"
            android:maxLines="2"
            android:minHeight="@dimen/alert_dialog_button_bar_height"
            style="?android:attr/buttonBarButtonStyle"
            android:textSize="14sp"
            android:layout_height="wrap_content" />
    </LinearLayout>
 </LinearLayout>

Ответ 3

Я знаю, что это не ответ на вашу проблему, но почему вы не хотите, чтобы стиль Activity выглядел как Dialog? У меня была такая же проблема, как у вас, и стиль Android Dialog очень болезнен. Используя Activity, вы можете поместить все, что хотите, в качестве xml-контента и стилизовать его по своему усмотрению. Также у вас есть ActionBar, чтобы вы могли добавить меню в свой Dialog и использовать пользовательские представления в ActionBar. Возможно, пришло время изменить ваши диалоги для Android на Activity с помощью стиля Dialog.

Ответ 4

Попробуйте этот стиль:

<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>