我正在创建类并设置文本样式。我已经在attrs和stylable and Style中定义了,使Getter Setter和SET TEXTSTYLE BOLD仍然不会变得大胆。如何设置大胆的文本?plz帮助?
<declare-styleable name="CustomTagGroup">
<attr name="descriptionTextStyle" format="flags">
<flag name="normal" value="0" />
<flag name="bold" value="1" />
<flag name="italic" value="2" />
<flag name="bolditalic" value="3" />
</attr>
<style name="CustomTagGroup">
<item name="atg_horizontalPadding">12dp</item>
<item name="atg_verticalPadding">3dp</item>
<item name="android:textStyle">bold</item>
<item name="descriptionTextStyle">bolditalic</item>
</style>
final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.CustomTagGroup, defStyleAttr, R.style.CustomTagGroup);
try {
a.getType(R.styleable.CustomTagGroup_descriptionTextStyle);
int bold = Typeface.BOLD_ITALIC;
textStyle = a.getInt(R.styleable.CustomTagGroup_descriptionTextStyle, bold);
}catch(Exception e){
e.printStackTrace()
}
这是您的自定义类,它扩展了 textView ?如果是,则首先获得属性taht,您在XML中定义了:
<com.package.CustomTextView
......
app:text_style = "1"
/>
采用属性值后,添加setbold by Dower code
@Override
protected void onFinishInflate() {
super.onFinishInflate();
// set your if else condition that come from attr
// Like you get 1 then execute below line
this.setTypeface(getTypeface(),Typeface.BOLD);
}