I have a theme where on wanted all textviews on activities to be capitalized. So I set textAllCaps in a style and then applied it to textViewStyle in my theme like the below
<style name="Widget.Apex.TextView" parent="android:Widget.TextView">
<item name="android:textAppearance">?android:attr/textAppearanceSmall</item>
<item name="android:textAllCaps">true</item>
</style>
<style name="MyTheme" parent="@android:style/Theme.Holo">
<item name="android:textViewStyle">@style/Widget.Apex.TextView</item>
</style>
Unfortunately this had the side effect of turning my Application Title, ActionBar subtitles, and popmenu items capitalized. So I thought I would just set the ActionBarStyle, textAppearanceLargePopupMenu, and textAppearanceSmallPopupMenu attributes in my theme to have a custom style with textAllCaps=false. However, this does not work. I know my themes are being applied because if I set textColor or textStyle they are both applied to the titles and menu items. Is it possible to override the textAllCaps in these styles?
<style name="Widget.Apex.TextView" parent="android:Widget.TextView">
<item name="android:textAppearance">?android:attr/textAppearanceSmall</item>
<item name="android:textAllCaps">true</item>
</style>
<style name="TextAppearance.Apex.Widget.ActionBar.Title" parent="android:TextAppearance.Holo.Widget.ActionBar.Title">
<item name="android:textAllCaps">false</item>
<item name="android:textStyle">italic</item>
</style>
<style name="TextAppearance.Apex.Widget.ActionBar.Subtitle" parent="android:TextAppearance.Holo.Widget.ActionBar.Subtitle">
<item name="android:textAllCaps">false</item>
<item name="android:textStyle">italic</item>
<item name="android:textColor">#FF0000</item>
</style>
<style name="TextAppearance.Apex.Widget.PopupMenu.Large" parent="android:TextAppearance.Holo.Widget.PopupMenu.Large">
<item name="android:textAllCaps">false</item>
<item name="android:textStyle">italic</item>
<item name="android:textColor">#FF0000</item>
</style>
<style name="TextAppearance.Apex.Widget.PopupMenu.Small" parent="android:TextAppearance.Holo.Widget.PopupMenu.Small">
<item name="android:textAllCaps">false</item>
<item name="android:textStyle">italic</item>
<item name="android:textColor">#FF0000</item>
</style>
<style name="Widget.Apex.ActionBar" parent="android:Widget.Holo.ActionBar">
<item name="android:titleTextStyle">@style/TextAppearance.Apex.Widget.ActionBar.Title</item>
<item name="android:subtitleTextStyle">@style/TextAppearance.Apex.Widget.ActionBar.Subtitle</item>
</style>
<style name="MyTheme" parent="@android:style/Theme.Holo">
<item name="android:actionBarStyle">@style/Widget.Apex.ActionBar</item>
<item name="android:textAppearanceLargePopupMenu">@style/TextAppearance.Apex.Widget.PopupMenu.Large</item>
<item name="android:textAppearanceSmallPopupMenu">@style/TextAppearance.Apex.Widget.PopupMenu.Small</item>
<item name="android:textViewStyle">@style/Widget.Apex.TextView</item>
</style>
Thanks, Jonathan
If you are using an Android phone and Gboard, you can capitalize the first letter of any word with three touches. First, double-tap the word in question to highlight the word, then tap the shift button (the up arrow) on the keyboard to capitalize the first letter. Done!
TextAppearance allows you to define text-specific styling while leaving a View 's style available for other uses. Note, however, that if you define any text attributes directly on the View or in a style, those values would override the TextAppearance values.
Try with both textAllCaps
and android:textAllCaps
.
<style name="TextViewStyle">
<item name="textAllCaps">true</item>
<item name="android:textAllCaps">true</item>
</style>
But I think it's working just with design library 23.2.0 or later.
By using AppCompat textAllCaps
in Android Apps supporting older API's (less than 14)
A work around for this would to explicitly set the style like this:
<android.support.v7.internal.widget.CompatTextView
style="@style/MyTextViewStyle"
android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:textAllCaps="true"/>
or alternatively use a new style that inherits textViewStyle and adds the textAllCaps attribute along with any other styles of your choosing:
<style name="MyCompatTextViewStyle" parent="MyTextViewStyle">
<item name="textAllCaps">true</item>
</style>
In layout:
<android.support.v7.internal.widget.CompatTextView
style="@style/MyCompatTextViewStyle"
android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
Note:
1> this widget won't inherit any default styles that are set in your theme via android:textViewStyle
2>Using this widget seems to be internal given the package name meaning it's not really intended for public API. It's also not "fully baked" in that the textAllCaps
attribute needs to be directly on the style/view and can not be in the textAppearance style for it to work.
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