android添加第三方字体并设置的简单使用

2023-07-29,,

1、java文件

    package lpc.com.project006; import android.app.Activity; import android.content.res.AssetManager; import android.graphics.Typeface; import android.os.Bundle; import android.widget.EditText; /** * 此程序没有什么高神的功能,只是一个添加第三方字体,并且应用的功能 * * 1、犯了一个比较二的错误,assets的位置不对,assents的正确位置是src/main 下 * 2、对于字体因为太大而导致的问题,可以将字体的扩展名改成zip或者jpg就会解决、 * */ public class MainActivity extends Activity { private EditText et; private Typeface tf; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); et = (EditText) findViewById(R.id.et); AssetManager mgr=getAssets();//得到AssetManager tf = Typeface.createFromAsset(mgr, "fonts/1.zip");//根据路径得到Typeface et.setTypeface(tf);//设置字体 } }

2、布局文件

里面只有一个简单的editview

    <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context="lpc.com.project006.MainActivity"> <EditText android:id="@+id/et" android:layout_width="match_parent" android:layout_height="wrap_content" android:hint="请输入电话号码" /> </RelativeLayout>

3、manfests文件

    <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="lpc.com.project006"> <application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:supportsRtl="true" android:theme="@style/AppTheme"> <activity android:name=".MainActivity"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> </manifest>

4、字体文件

http://pan.baidu.com/s/1i3OL5jB 华康少女字体

5、运行效果

来自为知笔记(Wiz)

android添加第三方字体并设置的简单使用的相关教程结束。

《android添加第三方字体并设置的简单使用.doc》

下载本文的Word格式文档,以方便收藏与打印。