What's happened to Monospace in Android Lollipop?

偶尔善良 提交于 2019-12-21 08:17:13

问题


I have a style to use "monospace" in my Android App:

<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:android="http://schemas.android.com/apk/res/android">
    <!-- Base application theme. -->
    <style name="AppTheme"  parent="Theme.AppCompat.Light.DarkActionBar" >
        <!-- Customize your theme here. -->
        <item name="android:windowNoTitle">true</item>
        <item name="android:typeface">monospace</item>
        <item name="android:textColorPrimary">@android:color/white</item>
        <item name="android:itemTextAppearance">@style/MenuText</item>
   </style>

   <style name="M13Text">
        <item name="android:typeface">monospace</item>
        <item name="android:textColor">@android:color/white</item>
        <item name="android:textColorLink">@android:color/holo_red_light</item>
   </style>

   <style name="MenuText">
       <item name="android:typeface">monospace</item>
       <item name="android:textColor">@android:color/black</item>
   </style>
</resources>

All was fine until Lollipop arrived when it doesn't seem use the Monospace font anymore and I can see it change when I flip APIs from 19 to 21 in Android Studio.

I've googled and not found anything and I appreciate it is just a cosmetic issue but anyone got any ideas as to why?


回答1:


The Material text appearances specify the android:fontFamily attribute rather than android:typeface so that they can use sans-serif-light, sans-serif-medium, etc. This attribute takes precedence over typeface, so you will need to either override or clear the fontFamily value.

<style name="MenuText">
    <item name="android:fontFamily">monospace</item>
    ...
</style>


来源:https://stackoverflow.com/questions/29076599/whats-happened-to-monospace-in-android-lollipop

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