Java 在xml布局中调用时,我的自定义文本视图太长
我创建了一个自定义textview以使用自定义字体从文件夹资产中获取,这是我编写的一个类:Java 在xml布局中调用时,我的自定义文本视图太长,java,android,xml,view,Java,Android,Xml,View,我创建了一个自定义textview以使用自定义字体从文件夹资产中获取,这是我编写的一个类: public class TextViewBold extends TextView { private void init() { Typeface face = Typeface.createFromAsset(getContext().getAssets(),"fonts/droid-sans.bold.ttf"); setTypeface(f
public class TextViewBold extends TextView
{
private void init()
{
Typeface face = Typeface.createFromAsset(getContext().getAssets(),"fonts/droid-sans.bold.ttf");
setTypeface(face);
setTextSize(14);
setTextColor(getContext().getResources().getColor(R.color.black));
}
public TextViewBold(Context context)
{
super(context);
init();
}
public TextViewBold(Context context, AttributeSet attrs)
{
super(context, attrs);
init();
}
}
我还创建了另外两个扩展TextView的类
然后我在xml布局中将其称为:
<com.cmc.xcharge.widget.TextViewBold
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#ff00ff"
android:text="hello" />
我构建并运行成功,但这行代码:com.cmc.xcharge.widget.TextViewBold太长,无法使用,我希望使用如下代码:
<TextViewBold
/>
我该怎么办?我认为你必须使用long way,因为它不是android默认视图,你可以自定义它,因此需要指定它的包名。如果你可以在类中定义字体,那么为其余装饰定义样式是一个不错的选择。