1
我正在创建各种Android窗口小部件的子类来创建我自己的窗口小部件。以下是我迄今所做的:自定义窗口小部件中使用的自定义XML属性
(在我的RES /价值/ attr.xml定义)
<attr name="font">
<enum name="ARIAL_BOLD" value="1" />
<enum name="ARIAL_ROUND_MT" value="2" />
<enum name="HELVETICA" value="3" />
<enum name="HELVETICA_BOLD" value="4" />
<enum name="GILSANCE_LIGHT" value="4" />
</attr>
<declare-styleable name="EditText">
<attr name="font" />
</declare-styleable>
<declare-styleable name="Button">
<attr name="font" />
</declare-styleable>
<declare-styleable name="TextView">
<attr name="font" />
</declare-styleable>
然后在我的EditText
我以这个为:
public class EditText extends android.widget.EditText {
public EditText(Context context) {
super(context);
}
public EditText(Context context, AttributeSet attrs) {
super(context, attrs);
TypedArray a = context.obtainStyledAttributes(attrs,
R.styleable.EditText);
}
}
现在我想读取已在XML代码中设置的枚举的值。我如何阅读它?然后,根据提供的字体,我想设置我的自定义字体。任何帮助将不胜感激。
我曾尝试过,但卡住了。当我终于得到答案时,我与你们分享了它。没有伤害完成。 – AndroidDev