mikepenz/Android-Iconics

How to use in XML

DanteAndroid opened this issue · 4 comments

Use via XML
If you use the Iconics library via XML provide the icon you want to use in the following syntax: gmd-favorite --> fontId-iconName. A list of the available fonts and their fontId can be found here. All icon names from the default fonts can be found via the DEMO application.

I don't understand. What I want is like

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:drawableEndCompat="@drawable/**here_is_what_i_need**"
 />

If you are above API level 24 you can use a custom drawable which includes your icon:

https://github.com/mikepenz/Android-Iconics#drawable-xml-api-24

for example define a drawable drawable/myicon.xml with

<com.mikepenz.iconics.IconicsDrawable
    xmlns:app="http://schemas.android.com/apk/res-auto"
    app:ico_icon="gmd_favorite"
    app:ico_color="#0000FF"
    app:ico_contour_width="1dp"
    app:ico_contour_color="#00FFFF"
    app:ico_size="24dp" />

and then you can use

<TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:drawableEndCompat="@drawable/myicon"
 />

It's more recommended though to use the library programmatically as it gives you a lot more flexibility. this will allow you to use any progammatic exposed API from TextViews

Alternative you can use one of the provided IconicsView*s which expose custom attributes to work with iconics:
https://github.com/mikepenz/Android-Iconics#as-iconicsimageview

The sample app also highlights a few of those scenarios

Thanks. I thought this library compiles drawable resources for convenient use. Seems that is not a practical way?

That would break the disadvantage of flexible font rendering. If raster graphics would be created during compilation time those would not have the benefit of infinite scaling or things like flexible applying of contour color and things.

API 24 allows to use the lib similar like a drawable but that was sadly not possible before in android