Android textAllCaps in Theme

纵然是瞬间 提交于 2019-11-30 08:58:27

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.

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!