是否可以让用户自定义 .9 可绘制对象的颜色?
和标题说的差不多。我希望用户可以选择自定义我拥有的 9 个可绘制对象的边框。类似的事情可能吗,还是我需要使用不同的方法?现在,我认为它不会起作用,而且会弄乱 9 补丁。
Pretty much what the title says. I'm wanting the user to have the choice to customize the boarder of a 9 drawable I have. Is something like that possible or do I need to use a different method? Right now, I think it won't work and it will mess up the 9 patch.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
可以发一下你的9片的照片吗?可以将其部分提取到另一种类型的可绘制对象中,然后使用图层列表将可定制部分(使用用户定义的颜色绘制)分层到固定部分下。
[更新]根据您发布的图片,我会放弃图层列表的想法,但我们仍然可以解决一些问题。这个想法是从 9 块中完全删除彩色边框和内部深色背景(用阴影颜色和不透明度填充该区域)。然后将 3 个布局相互嵌套。第一个将使用 9 块作为背景。第二个将使用用户定义的颜色作为背景。第三个将使用您的面板颜色作为背景。 9 补丁将提供适当的边距来定位第二个(用户颜色)布局,然后您只需向第二个面板添加一个layout_margin 属性,以将最内部的布局定位在几个 dps 中。
当然,您' d 负责在代码中查找
PanelUserBorder
视图并调用setBackgroundColor()
使用正确的用户定义颜色。Can you post a picture of your 9-patch? It might be possible to extract parts of it to another type of drawable, then layer the customizable part (drawn with user defined color) under the fixed portions using a layer-list.
[Update] Based on the pic you posted, I'd trash the layer list idea, but we can still work something out. The idea would be to remove the colored border and internal dark background from the 9-patch entirely (fill that area in with the shadow color and opacity). Then nest 3 layouts in each other. The first would use the 9-patch as a background. The second would use the user-defined color as a background. The third would use your panel color as a background. The 9-patch would provide the proper margins to position the second (user-color) layout, and then you'd just add a layout_margin attribute to the second panel to position the inner most layout a few dps in.
Of course, you'd be responsible for finding the
PanelUserBorder
view in code and callingsetBackgroundColor()
with the proper user-defined color.也许您可以通过在按钮上方放置 50% 透明视图来为其着色。
经过思考,我想也许你可以通过位图转换颜色:
如何在android中改变位图图像颜色?
maybe you could tint it by putting a 50% transparent view overtop the button.
after thinking about it i thought maybe you could transform the color by bitmap:
How to change Bitmap image color in android?