current position:Home>Android studio uses iconfont Ali vector icon library

Android studio uses iconfont Ali vector icon library

2022-06-24 08:42:06Simon66991

stay Android Studio Medium src Folder right-click

 Insert picture description here

single click New, establish Assets Folder

 Insert picture description here
 Insert picture description here
 Insert picture description here
 Insert picture description here

stay assets So let's make a new one iconfont Catalog

take iconfont.ttf Copied to the iconfont Under the table of contents

 Insert picture description here

stay res/values/strings.xml, add to string value

 Insert picture description here

 Insert picture description here

Test a wave , stay xml Write a TextView, And then again Activity Under the settings in Typeface

xml Layout

 Insert picture description here

Activity
 Insert picture description here

Encapsulate a class , No need to set it manually Typeface

 Insert picture description here

Customize TextView, stay xml You can use , No need to Activity Manual setting in Typeface 了

package com.simon.view;

import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.Typeface;
import android.util.AttributeSet;
import android.widget.TextView;

/** *  The creator : Simon *  Creation time :2021/8/18 10:06 *  describe : */
@SuppressLint("AppCompatCustomView")
public class FontIconView extends TextView {
    

    public FontIconView(Context context) {
    
        super(context);
        init(context);
    }

    public FontIconView(Context context, AttributeSet attrs) {
    
        super(context, attrs);
        init(context);
    }

    public FontIconView(Context context, AttributeSet attrs, int defStyle) {
    
        super(context, attrs, defStyle);
        init(context);
    }

    /** *  initialization  * @param context  Context  */
    private void init(Context context) {
    
        // Set font icon 
        Typeface font = Typeface.createFromAsset(context.getAssets(), "iconfont/iconfont.ttf");
        this.setTypeface(font);
    }
}

copyright notice
author[Simon66991],Please bring the original link to reprint, thank you.
https://en.qdmana.com/2022/175/202206240608210883.html

Random recommended