在android中如何在自定义视图之间共享attrs
我创建了许多自定义视图,并且任何视图都有一个自定义属性:mystyle。
所以在我的 attr.xml 中:
<resources>
<declare-styleable name="MyView1">
<attr name="mystyle" format="string" />
</declare-styleable>
<declare-styleable name="MyView2">
<attr name="mystyle" format="string" />
</declare-styleable>
<declare-styleable name="MyView2">
<attr name="mystyle" format="string" />
</declare-styleable>
...
</resources>
我认为这不是恩典。有没有办法对所有客户视图使用一个属性?
I created many custom Views and any of views has a custom attribute: mystyle.
so that in my attr.xml:
<resources>
<declare-styleable name="MyView1">
<attr name="mystyle" format="string" />
</declare-styleable>
<declare-styleable name="MyView2">
<attr name="mystyle" format="string" />
</declare-styleable>
<declare-styleable name="MyView2">
<attr name="mystyle" format="string" />
</declare-styleable>
...
</resources>
I think that's not grace. Is there any way to use one attr for all the custome view?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以尝试制作
抽象ParentView
并为其声明属性。然后你所有的自定义视图都将扩展ParentView
,并且属性将被声明You can try to make
abstract ParentView
and declare attribute for it. Then all your custom views will extendParentView
, and attribute will be declared