【发布时间】:2013-10-08 12:49:52
【问题描述】:
我想使用 android 中具有相同字体类型的所有组件,为此我正在为每个组件创建一个单独的自定义类,如 CustomTextView、CustomEditText 等......
因此,我可以创建一个视图 CustomView 类来自动为 android 中的所有组件应用样式,而不是为每个组件创建一个单独的类
【问题讨论】:
标签: android view android-custom-view
我想使用 android 中具有相同字体类型的所有组件,为此我正在为每个组件创建一个单独的自定义类,如 CustomTextView、CustomEditText 等......
因此,我可以创建一个视图 CustomView 类来自动为 android 中的所有组件应用样式,而不是为每个组件创建一个单独的类
【问题讨论】:
标签: android view android-custom-view
只需声明你自己的 TextView 并在你的 XML 中使用它,它应该会出现在自定义视图中
public class MyTextView extends TextView {
public MyTextView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
setType(context);
}
public MyTextView(Context context, AttributeSet attrs) {
super(context, attrs);
setType(context);
}
public MyTextView(Context context) {
super(context);
setType(context);
}
private void setType(Context context){
this.setTypeface(Typeface.createFromAsset(context.getAssets(), "chalk_board.ttf"));
}
哦,老妈,你希望它在全局范围内用于所有视图,所以这是错误的方法.... 抱歉
【讨论】:
你至少有两种方法:
【讨论】: