2016-02-29 45 views
2

我有一個TextView,並且我想沿着它的頂部和底部邊緣添加具有不同顏色的邊框。我知道,序沿着所有的邊緣,我們可以簡單地使用下面的代碼添加一種顏色的邊框:向Android視圖的頂部和底部邊緣添加不同顏色邊框的方法

<?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> 

但需要,如果我們需要用不同的顏色的邊緣做什麼?

回答

2

你非常接近你想要的,你需要做的是在你的默認項目下添加另一個項目。這兩個項目是你的頂部/底部邊界。通過向兩者添加底部/頂部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> 
+0

謝謝你工作得很好:) –

相關問題