Android 获取styles.xml中textStyle属性的相同值
我正在尝试提取此属性的值集Android 获取styles.xml中textStyle属性的相同值,android,Android,我正在尝试提取此属性的值集bold 根据文档,此属性的返回值为 正常:0 粗体:1 斜体:2 但是无论在textStyle中传递什么,我总是为styleVal得到0! 代码中的所有内容似乎都正确,我无法调试错误 private void getTextViewStyleValue() { int[] AttrSet = { android.R.attr.textColor, android.R.attr.textS
bold
根据文档,此属性的返回值为
正常:0
粗体:1
斜体:2
但是无论在textStyle中传递什么,我总是为styleVal
得到0!
代码中的所有内容似乎都正确,我无法调试错误
private void getTextViewStyleValue() {
int[] AttrSet = {
android.R.attr.textColor,
android.R.attr.textStyle,
android.R.attr.fontFamily,
};
TypedArray a = context.obtainStyledAttributes(style, AttrSet);
textColor = a.getColor(0, DEFAULT_TEXT_COLOR);
int styleVal = a.getInt(1, 0);
font = Typeface.createFromAsset(context.getAssets(), a.getString(2));
a.recycle();
}
这是关于android.R.attr.textStyle值的文章
请尝试使用.getInteger,因为它是一个枚举。@Mihai没有任何区别,请参阅我更新的帖子。您不应该再次声明系统声明的属性,如果需要使用,您需要这样做