如何更改相对布局的边框颜色?

5

如何更改相对布局的边框颜色?以下是我的代码,我只想显示黑色边框,但它显示所有相对布局为黑色。我只想显示相对布局白色,只有边框是黑色,我该怎么做?

<RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/border5">

<?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:left="1dp"  android:top="1dp" android:bottom="2dp" >  
         <shape android:shape="rectangle"> 
         </shape>
      </item>    
</layer-list> 
1个回答

18

这是我如何给它加上白色背景和橙色边框

    <shape xmlns:android="http://schemas.android.com/apk/res/android"    
    android:shape="rectangle" >

    <solid android:color="@drawable/white" />

    <stroke
        android:width="3px"
        android:color="@drawable/orange" />

   </shape>
如果你只是想要一个边框,可以在同一个 <shape> 中使用 <solid...> 设置 background 颜色(如果需要的话),并使用 <stroke...> 设置边框。
你可以按照现有方式进行,只需将 <solid> 更改为所需的 background 颜色,并添加带黑色的 <stroke>

嗨,使用dp而不是px会更好。 - Deivison Sporteman

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接