在LinearLayout中更改分隔线的颜色 [英] Change the color of divider in LinearLayout
问题描述
我可以知道如何更改LinearLayout
中分隔线的颜色吗?
May I know how I can change the color of divider in LinearLayout
?
<LinearLayout
android:layout_width="match_parent"
android:layout_height="48dp"
android:orientation="horizontal"
android:divider="?android:attr/dividerVertical"
android:dividerPadding="12dip"
android:showDividers="middle"
android:background="#ff2d2d2d" >
...
</LinearLayout>
我需要从Android SDK中手动复制9个补丁程序映像到我的项目中,并定义自己的属性来引用它吗?
Do I need to manually copy 9 patch image from Android SDK into my project, and define my own attribute to refer it?
推荐答案
android:divider
属性似乎不接受颜色值.因此,您必须创建一个单独的分隔器drawable才能起作用:
It looks like android:divider
attribute doesn't accept a color value. So you have to create a separate divider drawable in order to get it works:
divider.xml
divider.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<size android:width="1dip" />
<solid android:color="#f00" />
</shape>
layout.xml
layout.xml
<LinearLayout
android:layout_width="match_parent"
android:layout_height="48dp"
android:orientation="horizontal"
android:divider="@drawable/divider"
android:dividerPadding="12dip"
android:showDividers="middle"
android:background="#ff2d2d2d" >
此外,请注意,android:divider
仅在android 3.0或更高版本中可用,并且在以前的android版本中不起作用.
Also, please note that android:divider
is only available in android 3.0 or higher and it doesn't work in previous android versions.
这篇关于在LinearLayout中更改分隔线的颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!