android - 在 Kotlin 中以编程方式更改可绘制的描边颜色 - Android Studio
问题描述
我正在尝试更改用作背景的 Drawable 笔划的颜色。
这是我的可绘制对象:
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<solid android:color="@color/colorPrimary" />
</shape>
</item>
<item
android:id="@+id/item_border_drawable"
android:left="16dp"
android:right="16dp"
android:top="16dp"
android:bottom="16dp">
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<!-- This is the stroke you want to define -->
<stroke android:width="3dp"
android:color="@color/itemLegendary"/>
<!-- Optional, round your corners -->
<corners android:bottomLeftRadius="0dp"
android:topLeftRadius="5dp"
android:bottomRightRadius="5dp"
android:topRightRadius="0dp" />
</shape>
</item>
</layer-list>
如您所见,我使用一个项目 Rectangle 来获得背景颜色,然后在顶部使用另一个矩形,在它周围绘制一个边框,但周围有 16dp 的边距。
我想在 MainActivity 中更改笔触的颜色,而不影响填充和背景颜色。
我尝试按照此处提到的方式进行操作: Android以编程方式更改颜色描边(边框) 但是它似乎没有“更改颜色”而是替换了整个Drawable,我不想提供填充等信息。 。 再次。
你们能帮我轻松更改边框的颜色吗?
问候。
解决方案
推荐阅读
- android - 致命异常:尝试在空对象引用 getItemCount 上调用接口方法“int java.util.List.size()”
- python - 如何使用 tkinter python 拖动矩形中的全部内容?
- python - 替换文件中两个字符之间的字符串
- android - Flutter 如何平滑地为标记设置动画?
- google-analytics - 如何计算访问次数最多的页面,不包括 Google Analytics 上的目标页面访问?
- javascript - 多个键的 JSON 过滤运行缓慢
- database - MongoDB - 将两个集合嵌入到一个集合中
- sql-server - 使用内部联接的直接查询和使用内部联接包含另一个选择查询有什么区别?
- c - sbrk 的返回值上下文中的“(void*)-1”是什么?
- python - 熊猫:一对多加入+剩余余额新行:拆分合同与发票