我有一个 TextView,我想在其顶部和底部边缘添加不同颜色的边框。我知道为了沿着所有边缘添加一种颜色的边框,我们可以简单地使用以下代码:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<solid android:color="#000000"/>
</shape>
</item>
<item
android:top="1dp" android:bottom="1dp">
<shape android:shape="rectangle">
<solid android:color="#ffffff"/>
</shape>
</item>
但是如果我们需要不同颜色的边,需要做什么呢?
最佳答案
你已经很接近你想要的了,你需要做的是在你的默认项目下面添加另一个项目。这两项是您的顶部/底部边框。通过向两者添加 bottom/top 1dp,您可以显示两种颜色。
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:bottom="1dp">
<shape android:shape="rectangle">
<solid android:color="#000000"/>
</shape>
</item>
<item
android:top="1dp">
<shape android:shape="rectangle">
<solid android:color="#000000"/>
</shape>
</item>
<item
android:top="1dp" android:bottom="1dp">
<shape android:shape="rectangle">
<solid android:color="#ffffff"/>
</shape>
</item>
</layer-list>
关于android - 将不同颜色的边框添加到android View 的顶部和底部边缘的方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35705896/