Templarian / MaterialDesign

✒7000+ Material Design Icons from the Community
https://materialdesignicons.com
Other
10.96k stars 717 forks source link

Add a strings.xml file to use the icons as a font in Android TextViews #3921

Open HugoMatilla opened 5 years ago

HugoMatilla commented 5 years ago

It is possible to use an icon font in Android inside TextViews. It will work on any Android version, and personally, I find it easy and convenient to use.

To achieve this there are only 3 steps needed:

1.- Add the font in the assets/fonts folder.

2.- Set the icon font in the TextView as its Typeface (There are many ways to do it)

      textView.typeface = Typeface.createFromAsset(getAssets(), "fonts/MaterialIconsFont.ttf");  

3.- Set the code of the icon as the text in the TextView

 <TextView
        android:layout_width="56sp"
        android:layout_height="56sp"
        android:text="@string/mdi_access_point"/>

What I am suggesting is to have an autogenerated string.xml file that would look like something like this.

<string name="mdi_access_point" translatable="false">&#xF002;</string>
<string name="mdi_access_point_network" translatable="false">&#xF003;</string>
<string name="mdi_access_point_network_off" translatable="false">&#xFBBD;</string>
<string name="mdi_account" translatable="false">&#xF004;</string>
...

Users who want to use this method instead of using Vector Drawables or 3rd party libraries could benefit from having an official "Material Design Icons" strings.xml instead of building it themselves.

Thank you in advance.

MrGrigri commented 5 years ago

This looks like something that will work on NPM (@mdi/xml). Maybe a new repo specifically for XML.