可以在样式中完全声明一个可以声明样式的属性(以避免命名冲突)吗?

时间:2018-09-13 15:11:07

标签: android

在以下样式中,button_csl可以完全符合其定义的样式的定义,例如

<item name="com.inc.app.LabeledButton:button_csl">@color/button_bar_csl_white</item>    

例如,这样它就不会与另一个属性发生冲突?

<!--ImageView-->
<style name="ButtonBar_LabeledButton_NavBar" parent="ButtonBar_LabeledButton">    
  <item name="com.inc.app:button_csl">@color/button_bar_csl_white</item>    
</style>

button_csl属性的定义如下所示

<declare-styleable name="LabeledButton">
  <attr name="button_csl" format="reference"></attr>
</declare-styleable>

但是,如果声明了具有相同属性的新可样式表,则如何解决冲突?

<declare-styleable name="NewStyleableButton">
  <attr name="button_csl" format="reference"></attr>
</declare-styleable>

在读取属性时,这似乎不是问题,因为它们的作用域是特定的可样式化(即Resource.Styleable.LabeledButton_button_csl

private void ReadAttributes(Context context, IAttributeSet attributes)
{
    Android.Content.Res.TypedArray typedArray = context.ObtainStyledAttributes(attributes, Resource.Styleable.LabeledButton);

    _button_csl = typedArray.GetResourceId(Resource.Styleable.LabeledButton_button_csl, 0);

    typedArray.Recycle();
}

但是,对于样式定义,似乎存在歧义

<!--ImageView-->
<style name="NewButtonStyle">
  <item name="com.inc.app:button_csl">@color/button_bar_csl_white</item>    
</style>

0 个答案:

没有答案