├── .gitattributes ├── .gitignore ├── .idea ├── caches │ └── build_file_checksums.ser ├── codeStyles │ └── Project.xml ├── gradle.xml ├── misc.xml ├── modules.xml └── runConfigurations.xml ├── README.md ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── tan │ │ └── texttypeface │ │ └── ExampleInstrumentedTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── assets │ │ └── fonts │ │ │ ├── BRUSHSCI.TTF │ │ │ ├── FZSTK.TTF │ │ │ ├── FZYTK.TTF │ │ │ ├── Raleway-Regular.ttf │ │ │ ├── SIMLI.TTF │ │ │ ├── SIMYOU.TTF │ │ │ ├── STHUPO.TTF │ │ │ ├── STXINGKA.TTF │ │ │ ├── fangsong.TTF │ │ │ └── simkai.ttf │ ├── java │ │ └── com │ │ │ └── tan │ │ │ └── texttypeface │ │ │ └── MainActivity.java │ └── res │ │ ├── layout │ │ └── activity_main.xml │ │ ├── mipmap-hdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-mdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxxhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ └── values │ │ ├── colors.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── test │ └── java │ └── com │ └── tan │ └── texttypeface │ └── ExampleUnitTest.java ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat └── settings.gradle /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/workspace.xml 5 | /.idea/libraries 6 | .DS_Store 7 | /build 8 | /captures 9 | .externalNativeBuild 10 | -------------------------------------------------------------------------------- /.idea/caches/build_file_checksums.ser: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xluu233/TextTypeFace/a2cec21ca6fc24d23730b6d509cce55bb4504b4a/.idea/caches/build_file_checksums.ser -------------------------------------------------------------------------------- /.idea/codeStyles/Project.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 15 | 16 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 17 | 18 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 19 | 31 | 32 | 33 | 34 | 35 | 36 | 38 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # TextTypeFace 2 | 简介:https://blog.csdn.net/qq_36332133/article/details/84563339 3 | 4 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 25 5 | buildToolsVersion '28.0.3' 6 | defaultConfig { 7 | applicationId "com.tan.texttypeface" 8 | minSdkVersion 19 9 | targetSdkVersion 25 10 | versionCode 1 11 | versionName "1.0" 12 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 13 | } 14 | buildTypes { 15 | release { 16 | minifyEnabled false 17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 18 | } 19 | } 20 | } 21 | 22 | dependencies { 23 | implementation fileTree(dir: 'libs', include: ['*.jar']) 24 | androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', { 25 | exclude group: 'com.android.support', module: 'support-annotations' 26 | }) 27 | implementation 'com.android.support:appcompat-v7:25.3.1' 28 | implementation 'com.android.support.constraint:constraint-layout:1.0.2' 29 | testImplementation 'junit:junit:4.12' 30 | } 31 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in D:\AndroidStudio\sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | 19 | # Uncomment this to preserve the line number information for 20 | # debugging stack traces. 21 | #-keepattributes SourceFile,LineNumberTable 22 | 23 | # If you keep the line number information, uncomment this to 24 | # hide the original source file name. 25 | #-renamesourcefileattribute SourceFile 26 | -------------------------------------------------------------------------------- /app/src/androidTest/java/com/tan/texttypeface/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package com.tan.texttypeface; 2 | 3 | import android.content.Context; 4 | import android.support.test.InstrumentationRegistry; 5 | import android.support.test.runner.AndroidJUnit4; 6 | 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | 10 | import static org.junit.Assert.*; 11 | 12 | /** 13 | * Instrumentation test, which will execute on an Android device. 14 | * 15 | * @see Testing documentation 16 | */ 17 | @RunWith(AndroidJUnit4.class) 18 | public class ExampleInstrumentedTest { 19 | @Test 20 | public void useAppContext() throws Exception { 21 | // Context of the app under test. 22 | Context appContext = InstrumentationRegistry.getTargetContext(); 23 | 24 | assertEquals("com.tan.texttypeface", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /app/src/main/assets/fonts/BRUSHSCI.TTF: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xluu233/TextTypeFace/a2cec21ca6fc24d23730b6d509cce55bb4504b4a/app/src/main/assets/fonts/BRUSHSCI.TTF -------------------------------------------------------------------------------- /app/src/main/assets/fonts/FZSTK.TTF: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xluu233/TextTypeFace/a2cec21ca6fc24d23730b6d509cce55bb4504b4a/app/src/main/assets/fonts/FZSTK.TTF -------------------------------------------------------------------------------- /app/src/main/assets/fonts/FZYTK.TTF: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xluu233/TextTypeFace/a2cec21ca6fc24d23730b6d509cce55bb4504b4a/app/src/main/assets/fonts/FZYTK.TTF -------------------------------------------------------------------------------- /app/src/main/assets/fonts/Raleway-Regular.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xluu233/TextTypeFace/a2cec21ca6fc24d23730b6d509cce55bb4504b4a/app/src/main/assets/fonts/Raleway-Regular.ttf -------------------------------------------------------------------------------- /app/src/main/assets/fonts/SIMLI.TTF: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xluu233/TextTypeFace/a2cec21ca6fc24d23730b6d509cce55bb4504b4a/app/src/main/assets/fonts/SIMLI.TTF -------------------------------------------------------------------------------- /app/src/main/assets/fonts/SIMYOU.TTF: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xluu233/TextTypeFace/a2cec21ca6fc24d23730b6d509cce55bb4504b4a/app/src/main/assets/fonts/SIMYOU.TTF -------------------------------------------------------------------------------- /app/src/main/assets/fonts/STHUPO.TTF: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xluu233/TextTypeFace/a2cec21ca6fc24d23730b6d509cce55bb4504b4a/app/src/main/assets/fonts/STHUPO.TTF -------------------------------------------------------------------------------- /app/src/main/assets/fonts/STXINGKA.TTF: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xluu233/TextTypeFace/a2cec21ca6fc24d23730b6d509cce55bb4504b4a/app/src/main/assets/fonts/STXINGKA.TTF -------------------------------------------------------------------------------- /app/src/main/assets/fonts/fangsong.TTF: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xluu233/TextTypeFace/a2cec21ca6fc24d23730b6d509cce55bb4504b4a/app/src/main/assets/fonts/fangsong.TTF -------------------------------------------------------------------------------- /app/src/main/assets/fonts/simkai.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xluu233/TextTypeFace/a2cec21ca6fc24d23730b6d509cce55bb4504b4a/app/src/main/assets/fonts/simkai.ttf -------------------------------------------------------------------------------- /app/src/main/java/com/tan/texttypeface/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.tan.texttypeface; 2 | 3 | import android.content.res.AssetManager; 4 | import android.graphics.Typeface; 5 | import android.support.v7.app.AppCompatActivity; 6 | import android.os.Bundle; 7 | import android.view.View; 8 | import android.widget.AdapterView; 9 | import android.widget.ArrayAdapter; 10 | import android.widget.Button; 11 | import android.widget.Spinner; 12 | import android.widget.TextView; 13 | 14 | public class MainActivity extends AppCompatActivity { 15 | 16 | TextView tv1,tv2,tv_size; 17 | Button add,reduce; 18 | Button style1,style2,style3,style4; 19 | Spinner spinner; 20 | 21 | int size = 15; //字体大小 22 | 23 | Typeface tf1,tf2,tf3,tf4,tf5,tf6,tf7,tf8,tf9,tf10; 24 | 25 | @Override 26 | protected void onCreate(Bundle savedInstanceState) { 27 | super.onCreate(savedInstanceState); 28 | setContentView(R.layout.activity_main); 29 | initView(); 30 | onClick(); 31 | 32 | } 33 | 34 | 35 | private void initView() { 36 | tv1 = (TextView) findViewById(R.id.tv1); 37 | tv2 = (TextView) findViewById(R.id.tv2); 38 | tv_size = (TextView) findViewById(R.id.tv_size); 39 | 40 | add = (Button)findViewById(R.id.tv_add); 41 | reduce = (Button)findViewById(R.id.tv_reduce); 42 | style1 = (Button) findViewById(R.id.tv_style1); 43 | style2 = (Button) findViewById(R.id.tv_style2); 44 | style3 = (Button) findViewById(R.id.tv_style3); 45 | style4 = (Button)findViewById(R.id.tv_style4); 46 | spinner = (Spinner) findViewById(R.id.spinner); 47 | 48 | String[] arr={"仿宋","幼圆-常规","华文行楷","BRUSHSCI斜体","方正姚体","华文琥珀","楷体-常规","方正舒体","Raleway-常规","隶书"}; 49 | ArrayAdapter adapter=new ArrayAdapter(this,android.R.layout.simple_spinner_dropdown_item,arr); 50 | spinner.setAdapter(adapter); 51 | 52 | //从asset 读取字体 53 | //得到AssetManager 54 | AssetManager mgr = getAssets(); 55 | //根据路径得到Typeface 56 | tf1 = Typeface.createFromAsset(mgr, "fonts/fangsong.TTF");//仿宋 57 | tf2 = Typeface.createFromAsset(mgr, "fonts/SIMYOU.TTF");//幼圆-常规 58 | tf3 = Typeface.createFromAsset(mgr, "fonts/STXINGKA.TTF");//华文行楷 59 | tf4 = Typeface.createFromAsset(mgr, "fonts/BRUSHSCI.TTF");//BRUSHSCI斜体 60 | tf5 = Typeface.createFromAsset(mgr, "fonts/FZYTK.TTF");//方正姚体 61 | tf6 = Typeface.createFromAsset(mgr, "fonts/STHUPO.TTF");//华文琥珀 62 | tf7 = Typeface.createFromAsset(mgr, "fonts/simkai.ttf");//楷体-常规 63 | tf8 = Typeface.createFromAsset(mgr, "fonts/FZSTK.TTF");//方正舒体 64 | tf9 = Typeface.createFromAsset(mgr, "fonts/Raleway-Regular.ttf");//Raleway-常规 65 | tf10 = Typeface.createFromAsset(mgr, "fonts/SIMLI.TTF");//隶书 66 | 67 | } 68 | 69 | 70 | private void onClick() { 71 | add.setOnClickListener(new View.OnClickListener() { 72 | @Override 73 | public void onClick(View v) { 74 | size ++; //字体++++ 75 | tv_size.setText(size+"sp"); 76 | tv1.setTextSize(size); 77 | tv2.setTextSize(size); 78 | } 79 | }); 80 | 81 | 82 | 83 | reduce.setOnClickListener(new View.OnClickListener() { 84 | @Override 85 | public void onClick(View v) { 86 | size --; //字体 ---- 87 | tv_size.setText(size+"sp"); 88 | tv1.setTextSize(size); 89 | tv2.setTextSize(size); 90 | } 91 | }); 92 | 93 | 94 | style1.setOnClickListener(new View.OnClickListener() { 95 | @Override 96 | public void onClick(View v) { 97 | tv1.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD));//加粗 98 | tv2.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD));//加粗 99 | } 100 | }); 101 | 102 | 103 | style2.setOnClickListener(new View.OnClickListener() { 104 | @Override 105 | public void onClick(View v) { 106 | tv1.setTypeface(Typeface.defaultFromStyle(Typeface.ITALIC));//斜体 107 | tv2.setTypeface(Typeface.defaultFromStyle(Typeface.ITALIC));//斜体 108 | } 109 | }); 110 | 111 | style3.setOnClickListener(new View.OnClickListener() { 112 | @Override 113 | public void onClick(View v) { 114 | tv1.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD_ITALIC));//加粗斜体 115 | tv2.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD_ITALIC));//加粗斜体 116 | } 117 | }); 118 | 119 | style4.setOnClickListener(new View.OnClickListener() { 120 | @Override 121 | public void onClick(View v) { 122 | tv1.setTypeface(Typeface.defaultFromStyle(Typeface.NORMAL));//正常 123 | tv2.setTypeface(Typeface.defaultFromStyle(Typeface.NORMAL));//正常 124 | } 125 | }); 126 | 127 | spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { 128 | @Override 129 | public void onItemSelected(AdapterView parent, View view, int position, long id) { 130 | switch (position){ 131 | case 0: 132 | tv1.setTypeface(tf1); 133 | tv2.setTypeface(tf1); 134 | break; 135 | case 1: 136 | tv1.setTypeface(tf2); 137 | tv2.setTypeface(tf2); 138 | break; 139 | case 2: 140 | tv1.setTypeface(tf3); 141 | tv2.setTypeface(tf3); 142 | break; 143 | case 3: 144 | tv1.setTypeface(tf4); 145 | tv2.setTypeface(tf4); 146 | break; 147 | case 4: 148 | tv1.setTypeface(tf5); 149 | tv2.setTypeface(tf5); 150 | break; 151 | case 5: 152 | tv1.setTypeface(tf6); 153 | tv2.setTypeface(tf6); 154 | break; 155 | case 6: 156 | tv1.setTypeface(tf7); 157 | tv2.setTypeface(tf7); 158 | break; 159 | case 7: 160 | tv1.setTypeface(tf8); 161 | tv2.setTypeface(tf8); 162 | break; 163 | case 8: 164 | tv1.setTypeface(tf9); 165 | tv2.setTypeface(tf9); 166 | break; 167 | case 9: 168 | tv1.setTypeface(tf10); 169 | tv2.setTypeface(tf10); 170 | break; 171 | default: 172 | break; 173 | } 174 | } 175 | 176 | @Override 177 | public void onNothingSelected(AdapterView parent) { 178 | 179 | } 180 | }); 181 | } 182 | } 183 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 11 | 18 | 19 | 23 | 24 | 31 | 32 | 36 | 37 | 38 | 43 | 44 |