Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/370.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 在xml布局中调用时,我的自定义文本视图太长_Java_Android_Xml_View - Fatal编程技术网

Java 在xml布局中调用时,我的自定义文本视图太长

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

我创建了一个自定义textview以使用自定义字体从文件夹资产中获取,这是我编写的一个类:

    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默认视图,你可以自定义它,因此需要指定它的包名。如果你可以在类中定义字体,那么为其余装饰定义样式是一个不错的选择。