7. Simply Maintain Your Icon Library

Keywords: Android xml encoding

I. Preface:

Developing new personal projects is often plagued by the lack of icons. Today, I'll teach you how to build your own icon library.

2. Establish icon library:

1, open iconfont
2. Login (no account can be registered)
3. Click on Icon Library - > Select Icon Library

4. Click and select any gallery, enter this page, and hover the mouse on any icon.

  • 1. Add to the warehouse: Select the icon to the temporary warehouse

  • 2. Collection: Add to the collection, you can find it in the following figure

  • 3. Download: Download in the form of pictures (you can set the format, size, color of the pictures you want to download)

5. Open the temporary collection, there will be the following three functional options

The following three functional options will appear:
- 1. Add to Project: Add Temporary Library to your Icon Library
- 2. Download material: batch download function (same as single download)
- 3. Download Code: Functions will be described in detail later.

Choose to add to the project and create a new demo project:

After the establishment:

So far, the establishment of personal icon library has been completed. How to use it?

3. Use personal icon library:

1. Select icons from the personal library that need to be used in projects

2. Choose the batch to join the shopping cart and choose the icon you need.

3. Select the download code

  • 1. After downloading, decompress

  • 2. Remove the useless part (the part not painted red), and get

4. Use in android
- 1. Copy the simplified code to the assets directory.

  • 2. Customize IconFontTextView
public class IconFontTextView extends TextView {
    public IconFontTextView(Context context) {
        super(context);
        initIconFont(context);
    }


    public IconFontTextView(Context context, AttributeSet attrs) {
        super(context, attrs);
        initIconFont(context);
    }

    public IconFontTextView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        initIconFont(context);
    }

    private void initIconFont(Context context) {
        Typeface iconfont = Typeface.createFromAsset(context.getAssets(), "icon_font/iconfont.ttf");
        setTypeface(iconfont);
    }

}
  • 3. Copy strings under Values and paste them into the current folder named string-icon-font

  • 4. Open the file demo_unicode.html and copy in the value of the red line.

  • 5. Reference in an XML file
<com.wd.fmm.leisure.view.IconFontTextView
                android:textSize="@dimen/activity_homepage_buttom_icon_size"
                android:gravity="center"
                android:text="@string/icon_font_home"
                android:textColor="@color/colorAccent"
                android:layout_width="30dp"
                android:layout_height="30dp" />
            <TextView
                android:textColor="@color/colorAccent"
                android:text="home page"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" />

Complete layout code:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <FrameLayout
        android:id="@+id/fl_root"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1">

    </FrameLayout>
    <include layout="@layout/incloud_divice_line"/>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="52dp">
        <LinearLayout
            android:gravity="center"
            android:orientation="vertical"
            android:layout_width="0dp"
            android:layout_weight="1"
            android:layout_height="match_parent">
            <com.wd.fmm.leisure.view.IconFontTextView
                android:textSize="@dimen/activity_homepage_buttom_icon_size"
                android:gravity="center"
                android:text="@string/icon_font_home"
                android:textColor="@color/colorAccent"
                android:layout_width="30dp"
                android:layout_height="30dp" />
            <TextView
                android:textColor="@color/colorAccent"
                android:text="@string/homepage_home"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" />
        </LinearLayout>

        <LinearLayout
            android:gravity="center"
            android:orientation="vertical"
            android:layout_width="0dp"
            android:layout_weight="1"
            android:layout_height="match_parent">
            <com.wd.fmm.leisure.view.IconFontTextView
                android:textSize="@dimen/activity_homepage_buttom_icon_size"
                android:gravity="center"
                android:text="@string/icon_font_hot"
                android:layout_width="30dp"
                android:layout_height="30dp" />
            <TextView
                android:text="@string/homepage_hot"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" />
        </LinearLayout>
        <LinearLayout
            android:gravity="center"
            android:orientation="vertical"
            android:layout_width="0dp"
            android:layout_weight="1"
            android:layout_height="match_parent">
            <com.wd.fmm.leisure.view.IconFontTextView
                android:textSize="@dimen/activity_homepage_buttom_icon_size"
                android:gravity="center"
                android:text="@string/icon_font_my"
                android:layout_width="30dp"
                android:layout_height="30dp" />
            <TextView
                android:text="@string/homepage_me"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" />
        </LinearLayout>
        <LinearLayout
            android:gravity="center"
            android:orientation="vertical"
            android:layout_width="0dp"
            android:layout_weight="1"
            android:layout_height="match_parent">
            <com.wd.fmm.leisure.view.IconFontTextView
                android:textSize="@dimen/activity_homepage_buttom_icon_size"
                android:gravity="center"
                android:text="@string/icon_font_settings"
                android:layout_width="30dp"
                android:layout_height="30dp" />
            <TextView
                android:text="@string/homepage_setting"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" />
        </LinearLayout>
    </LinearLayout>
</LinearLayout>

Fourth, the effect map:

Posted by xposed on Tue, 26 Mar 2019 06:39:28 -0700