您可以使用字样为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);
}
});
}
}