Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vue.js/6.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
Android 从stylable读取sp_Android - Fatal编程技术网

Android 从stylable读取sp

Android 从stylable读取sp,android,Android,我有一个自定义视图,需要从xml(可样式化)传递sp值。 我尝试的是: styleable.xml: <declare-styleable name="TagView"> <attr name="tagText" format="string"/> <attr name="tagTextSize" format="dimension"/> <attr name="tagTextColor" format="color" />

我有一个自定义视图,需要从xml(可样式化)传递sp值。 我尝试的是:

styleable.xml:

<declare-styleable name="TagView">
    <attr name="tagText" format="string"/>
    <attr name="tagTextSize" format="dimension"/>
    <attr name="tagTextColor" format="color" />
</declare-styleable>
但是它没有得到绝对的sp值(与密度相关)。。。如果我设置15sp,它就不会是15sp,而是一个非常大的尺寸,一个与密度无关的尺寸


我尝试了
typedArray.getDimension(R.styleable.TagView\u tagTextSize,0f)
,但结果相同…

请尝试以下方法:

tagSize = a.getDimensionPixelSize(R.styleable.TagView_tagTextSize, 0);

if (tagSize > 0) {
    nameTextView.setTextSize(TypedValue.COMPLEX_UNIT_PX, tagSize );
}

请尝试以下方法:

tagSize = a.getDimensionPixelSize(R.styleable.TagView_tagTextSize, 0);

if (tagSize > 0) {
    nameTextView.setTextSize(TypedValue.COMPLEX_UNIT_PX, tagSize );
}