我需要一些帮助,我已经浏览了一段时间,但是我找到的主题都无法解决我的问题。希望你能帮助我!
以下是问题描述:我有一个自定义视图,让我们称其为CustomView。它还有一些自定义属性,定义在attrs.xml文件中,如下所示:
这个视图是我想创建的库的一部分,以便在多个项目中使用。
有趣的部分在于:实际上,我会经常使用这个视图,所以我想在styles.xml中定义一个样式来定义它的属性,这样我就不必去编辑每个使用这个视图的xml布局文件的属性。类似于这样的东西:
我的问题是:如何定义“customViewStyle”键,并且如果可能的话,如何从中获取信息?
额外问题:我已经通过以下方式创建了这个“customViewStyle”键:
但我还没有找到如何利用它。
以下是问题描述:我有一个自定义视图,让我们称其为CustomView。它还有一些自定义属性,定义在attrs.xml文件中,如下所示:
<declare-styleable name="CustomView">
<attr name="customBackgroundColor" format="color"/>
<attr name="customTextColor" format="color"/>
<attr name="customWhatever" format="dimension"/>
</declare-styleable>
这个视图是我想创建的库的一部分,以便在多个项目中使用。
有趣的部分在于:实际上,我会经常使用这个视图,所以我想在styles.xml中定义一个样式来定义它的属性,这样我就不必去编辑每个使用这个视图的xml布局文件的属性。类似于这样的东西:
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="customViewStyle">@style/myCustomViewStyle</item>
</style>
<style name="myCustomViewStyle" parent="CustomViewStyle">
<item name="customBackgroundColor">@color/red</item>
<item name="customTextColor">@color/blue</item>
<item name="customWhatever">@dimen/someHeight</item>
</style>
我的问题是:如何定义“customViewStyle”键,并且如果可能的话,如何从中获取信息?
额外问题:我已经通过以下方式创建了这个“customViewStyle”键:
<attr name="customViewStyle" format="reference"/>
但我还没有找到如何利用它。