自定义组件TLPTextLabelAndData的styleable属性在<style>中设置无效求助
自定义UI组件样式中自定义属性不生效问题
我创建了一个自定义UI组件TLPTextLabelAndData,本质是线性布局内包含两个文本框。为控制每个文本控件的宽度,声明了如下styleable属性:
<declare-styleable name="TLPTextLabelAndData"> <attr name="labelWidth" format="dimension" /> <attr name="labelStyle" /> <attr name="labelText" /> <attr name="icon" /> <attr name="iconColor" /> <attr name="dataWidth" format="dimension" /> <attr name="dataStyle" format="reference" /> <attr name="dataText" format="string" /> </declare-styleable>
当在UI XML中直接设置这些属性时,组件工作正常:
<com.tlpsoftware.ui.TLPTextLabelAndData app:dataWidth="100dp" app:dataText="data 3" app:labelWidth="60dp" app:labelText="label 3" android:id="@+id/id_label_data_3" android:layout_width="match_parent" android:layout_height="wrap_content" app:dataStyle="@style/styleDataValue" app:labelStyle="@style/styleDataLabel" />
但将dataWidth或labelWidth放入<style>中时,属性值会被忽略:
<style name="styleDataValue"> <item name="dataWidth">200dp</item> <item name="android:paddingStart">8dp</item> <item name="android:typeface">normal</item> <item name="android:textSize">9pt</item> </style>
请问在样式表中引用dataWidth是否有其他方式?尝试app:dataWidth会报错,是否需要为style设置父类,或需将组件属性包裹在其他XML元素中才能在
相关产品推荐
相关产品推荐

