Missing TextAppearances.Micro style

邮差的信 提交于 2020-02-04 20:43:09

问题


According to Android Developer Design Style for Typography, there are 4 TextAppearances (Micro, Small, Medium, Large).

But there is no predefined style for Micro:

?android:attr/textAppearanceMicro
android:style/TextAppearance.Micro

None of them can be found in sources of Android. What am I missing?


回答1:


Good question! After researching a little bit, I didn't find any results for "TextAppearance.Micro".

On the other hand, I found the official Android source for style resource related to TextAppearances.

<style name="TextAppearance.Small">
    <item name="android:textSize">14sp</item>
    <item name="android:textColor">?textColorSecondary</item>
</style>

<style name="TextAppearance.Medium">
    <item name="android:textSize">18sp</item>
</style>

<style name="TextAppearance.Large">
    <item name="android:textSize">22sp</item>
</style>

As you can see, all of them only affect the text size (except TextAppearance.Small, which also affect the text color). So, I can safely say that the site displays the text sizes as a guideline only. On the other hand, you can always add a custom style to support TextAppearance.Micro! Just insert this inside styles.xml.

<style name="TextAppearance.Micro" parent="@android:style/TextAppearance.Small">
    <item name="android:textSize">12sp</item>
</style>

and use it like:

<TextView
    ...
    android:textAppearance="@style/TextAppearance.Micro" />

On a bit related note, when I searched "textAppearanceMicro", I found 3 projects on GitHub. All of them adding some custom attributes, which one of them is textAppearanceMicro. Also, all of them are using ActionBarSherlock. I don't know whether there is a connection between textAppearanceMicro and ActionBarSherlock, but I didn't find that attribute was used anywhere in the code.




回答2:


If you happen to use the Google AppCompat Library, you can use the following:

<TextView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:textAppearance="@style/TextAppearance.AppCompat.Caption" />


来源:https://stackoverflow.com/questions/24301329/missing-textappearances-micro-style

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