Android字体引入

2个方案:①xml引入、②java代码引入。

效果图:

方法①:xml引入:
1.创建font目录:

 

2.把字体库复制到font目录下:

 


3.xml中,使用fontFamily引入字体库:

<TextView
    android:text="@string/app_name"
    android:fontFamily="@font/led_"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"/>

方法①end...

方法②:java代码引入:
1.创建assets:

2.创一个fonts专用的文件夹:

3.把你的字体库拖(复制)到fonts文件夹:

4.使用:

public class MainActivity extends AppCompatActivity {

    @BindView(R.id.minute)
    TextView minute;
    @BindView(R.id.second)
    TextView second;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ButterKnife.bind(this);
        Typeface typeface = Typeface.createFromAsset(getAssets(),"fonts/led_.ttf");
        minute.setTypeface(typeface);
        second.setTypeface(typeface);

    }
    
}

方法②end...

猜你喜欢

转载自blog.csdn.net/qq_41873558/article/details/107749211