TextView 加载第三方字体 ttf文件
  HvTJUzsxOBtS 2023年11月25日 28 0



文章目录

  • 1、简介
  • 2、文件结构
  • 3、xingkai.ttf
  • 4、activity_main.xml
  • 5、Maniactivity 功能文件
  • 6、现象展示


1、简介

TextView 加载第三方字体文件

2、文件结构

TextView  加载第三方字体 ttf文件_ttf

3、xingkai.ttf

就是放在assets 资源文件下的第三方的 字体文件

4、activity_main.xml

就是布局文件

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

<LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginTop="30dp"
    android:layout_marginLeft="50dp"
    android:orientation="vertical">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/text_one_id"
        android:text="这是自带的字体"
        android:textSize="30dp"
        android:typeface="sans"/>


    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="40dp"
        android:id="@+id/text_two_id"
        android:text="这是第三方字体"
        android:textSize="30dp"/>


</LinearLayout>

</LinearLayout>
5、Maniactivity 功能文件
package com.example.tssh.mytexttypeface;

import android.graphics.Typeface;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.TextView;

import org.w3c.dom.Text;

public class MainActivity extends AppCompatActivity {

    private TextView textViewOwn;
    private Typeface typeface;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        textViewOwn = (TextView) findViewById(R.id.text_two_id);
        typeface = Typeface.createFromAsset(getAssets(),"xingkai.ttf"); //加载第三方字体

        textViewOwn.setTypeface(typeface); //设置第三方字体

    }
}
6、现象展示

TextView  加载第三方字体 ttf文件_第三方字体_02

【版权声明】本文内容来自摩杜云社区用户原创、第三方投稿、转载,内容版权归原作者所有。本网站的目的在于传递更多信息,不拥有版权,亦不承担相应法律责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@moduyun.com

  1. 分享:
最后一次编辑于 2023年11月25日 0

暂无评论

推荐阅读
  0piCg03t9xej   2023年12月23日   104   0   0 mavenxmlJavaJavamavenxml
HvTJUzsxOBtS