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>
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:
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>
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?
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With