在原生Android应用中使用字体图标是否是不良实践?

4

我打算在我的本地安卓应用中使用字体图标来替代png图片。我没有找到任何有关使用或不使用字体图标的建议。

那么,在本地安卓应用中使用字体图标是一种好的实践还是一种不好的实践呢?

(通过本地,我的意思是我不使用Webview作为用户界面)


1
这是一个好的实践。使用字体图标已经成为SVG的良好替代品(因为字体图标本身就是SVG,但它使用字体功能)。最近SVG的支持变得越来越好,但我不知道现在它有多好,或者它有多向后兼容。即使对于原生Java应用程序,字体图标也能很好地工作。我没有看到任何不使用它们的理由。 - Stephan Branczyk
1
你可以自由地使用它们,也可以创建自己的图标。 - Stanojkovic
1个回答

6

像世界上的其他实践一样,它也有其优点缺点

优点:

  • 更改图标颜色变得非常容易
  • 由于字体图标是SVG格式,它们可以缩放而不会出现视觉伪影(与缩放小的.png文件相比)
  • 相同数量的图标存储为.png文件所需的空间比字体图标少

缺点:

  • It's pretty inflexible, unless you can edit font and add new elements by yourself.
  • It's not readable:

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="\uE118"/>
    

    \uE118 and other unicodes are barely something you can keep in memory

  • You're forced to use custom typefaces everywhere you use icons, which leads to spaghetti code:

    • all TextViews should have ids
    • you set Typefaces everywhere in the code-behind

      (or, as I did, extend TextView class and setting Typeface based on the custom string attribute(with font path) you're passing in the xml)

  • You'd be surprise, how often people, who generate the fonts for you, change icons' codes. As a result, you can get pretty bizarre effects

我的个人观察:
对于快速构建原型,png格式更好;对于开发生产质量稳定的应用程序,图标字体更好。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接