Colorpicker 改变 9 个独立的绘图?
我有 9 个 ImageView,当 onClick 每个打开一个颜色选择器时,我希望颜色选择器更改与当时使用 onclick 的同一视图相关的可绘制颜色。我不确定如何进行此操作?我在网上搜索了示例,但似乎找不到任何相关的内容。
I have 9 ImageViews that when onClick each open a colorpicker, I would like have the colorpicker change the color of a drawable correlating to that same view that was used the onclick at that time. I am unsure of how to conduct this? I have searched for examples online but cant seem to find anything that is related.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您想要从中选择一组固定的颜色,则可以使用 级别列表可绘制。在 XML 中,它可能看起来像这样:
然后,您可以将其设为 的可绘制对象ImageView 并通过调用图像视图的
setImageLevel()
方法选择要显示的颜色。编辑
您要求提供以编程方式执行此操作的示例。假设您有以下布局:
然后,在您的活动中,定义您的处理程序函数,如下所示:
人们可能希望在此过程中包含一些检查以检查空标签、未找到的视图、用户取消颜色选择等。
If you have a fixed set of colors that you want to select from, you can use a level list drawable. In XML, it might look something like this:
You can then make this the drawable for an ImageView and select which color to display by calling the image view's
setImageLevel()
method.EDIT
You asked for an example of doing this programmatically. Let's say you have the following layout:
Then, in your activity, define your handler function something like this:
One might want to include some checking in this process for null tags, unfound views, the user canceling the color choice, etc.