Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The font style of the button text has changed for the AppCompatActivity

After changing the parent for my activity from Activity to AppCompatActivity, the font on the buttons changed. For example, Remove->REMOVE. For other Vews, the font has not changed.

Why did the font on the buttons change and how do I get the original font back?

Button:

            <Button
            android:id="@+id/buttonAddProduct"
            tools:text="Remove"
            android:layout_width="match_parent"
            android:textSize="13dp"
            android:layout_weight="1"
            style="@style/btns_blue_big" />

style:

<style name="btns_text_big">
    <item name="android:textSize">@dimen/text_size_big</item>
    <item name="android:textColor">@color/colorMainWhite</item>
</style>

<style name="btns_lo_big" parent="btns_text_big">
    <item name="android:layout_width">fill_parent</item>
    <item name="android:layout_height">48dp</item>
</style>

<style name="btns_blue_big" parent="btns_lo_big">
    <item name="android:background">@drawable/button_dialog_positive_shape</item>
</style>
like image 562
EfremovAV Avatar asked Dec 21 '17 10:12

EfremovAV


3 Answers

The change happens because of Google's Material Design theme.

Basically, when you change your Activity to AppCompatActivity, you are required to also change your app's theme to extend from Theme.AppCompat. This change causes the design for every view to match the theme.

Below are the example between Holo theme and AppCompat theme:

Holo Theme

Material / AppCompat Theme

As you can see, the button's default implementation in AppCompat theme uses all caps, so you will need to change those.

A simple fix would be to add these in your styles xml:

<style name="MyAppTheme" parent="Theme.AppCompat">
    <item name="buttonStyle">@style/MyAppTheme.Button</item>
    <item name="android:buttonStyle">@style/MyAppTheme.Button</item>
</style>

<style name="MyAppTheme.Button" parent="Base.Widget.AppCompat.Button">
    <item name="android:textAllCaps">false</item>
</style>
like image 175
Alvin Rusli Avatar answered Nov 12 '22 08:11

Alvin Rusli


Button text is all-caps by default when using the Material (or DeviceDefault with API 21+) theme. This is working as intended. If you do not want that you can use below attributes in your style

<item name="android:textAllCaps">false</item>
<item name="textAllCaps">false</item>

References is Why is my Button text forced to ALL CAPS on Lollipop?

like image 22
Pankaj Kumar Avatar answered Nov 12 '22 08:11

Pankaj Kumar


In Appcompat Theme, button texts are set to uppercase by default. I have no idea why. But if you want to disable it for that button in xml, set android:textAllCaps="false"

Programmatically: button.setTransformationMethod(null);

like image 1
islamdidarmd Avatar answered Nov 12 '22 07:11

islamdidarmd