关于android:如何避免CustomView中资源\\’attr/*\\’的重复值

How to avoid duplicate value for resource 'attr/*' in CustomView

如果我导入:

CustomViewA(从 Maven 导入)

<declare-styleable name="CustomViewA">
       
       
</declare-styleable>

CustomViewB(从 Maven 导入)

<declare-styleable name="CustomViewB">
       
       
</declare-styleable>

如果 min 和 max 重复,这将失败。我以为 Android 会通过 declare-styleable name 来区分,但猜不出来。话虽如此,命名自定义 View attr 以避免将来任何可能的重复值冲突的最佳方法是什么?

目前我得到的唯一解决方案是:

这太糟糕了。

相关讨论

  • 在引入命名空间之前,这是我们唯一的选择。
  • stackoverflow.com/a/4464966/4390987

你可以这样做

<declare-styleable name="CustomViewA">
   
   
</declare-styleable>

<declare-styleable name="CustomViewB">
   
   
</declare-styleable>

相关讨论

  • 如果我是 CustomViewA 所有者而不是 CustomViewB 所有者,这会起作用吗?假设 CustomViewB 开发人员在 declare-styleable 外部和/或内部使用 attr
  • 无法理解。你在说什么?
  • 假设在我的自定义库中,我使用了您的方法。然后我导入另一个使用相同方法的 Lib。会不会碰撞?
  • 抱歉耽搁了。不,它不会碰撞。如果两个库具有相同的 attr elements 它将正常工作
  • 是的,它可以在不同的模块中使用不同的格式和相同的名称正常工作
  • 不幸的是,如果 CustomViewA (maven import) 使用您的方法但 CustomViewB (maven import) 不使用,这将不起作用。刚测试过。

让它独一无二是最终的答案。
我准备使用


以上是关于android:如何避免CustomView中资源\\’attr/*\\’的重复值的全部内容。
THE END
分享
二维码
< <上一篇
下一篇>>