700字范文,内容丰富有趣,生活中的好帮手!
700字范文 > android应用添加字体 android中的自定义字体(适用于整个应用程序...

android应用添加字体 android中的自定义字体(适用于整个应用程序...

时间:2023-12-05 15:17:03

相关推荐

android应用添加字体 android中的自定义字体(适用于整个应用程序...

您可以使用字样为textview中的文本设置自定义字体.因此,每当需要textview的自定义字体时,都可以使用以下字体.

activity_main.xml中

android:orientation="vertical"

android:layout_width="fill_parent"

android:layout_height="fill_parent"

>

android:id="@+id/button1"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="Button" />

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:textColor="#FFF"

/>

编码:

public class MainActivity extends Activity {

private TextView text;

@Override

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

text = (TextView) findViewById(R.id.text);

Button b= (Button) findViewById(R.id.button1);

b.setOnClickListener( new OnClickListener()

{

@Override

public void onClick(View v) {

text.setText("This is a custom toast");

Typeface typeFace = Typeface.createFromAsset(getAssets(),"fonts/kn.ttf");

text.setTypeface(typeFace);

}

});

}

}

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。