为了更好地用户体验, 当用户点击的时候, 要给用户feedback, 在一个布局中, 点击的时候背景颜色改变, 但我们有时候又没有专门的设计人员,这时候就自己了.如下图:
点击的时候颜色会改变
布局的代码如下
android:orientation="horizontal"
//这里的background下面会说到
android:background="@drawable/layout_white_background"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:clickable="true"
>
android:textSize="16.0sp"
android:textColor="@color/text_light"
android:gravity="center"
android:layout_gravity="top"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10.0dip"
android:layout_marginTop="10.0dip"
android:text="签名"/>
android:textColor="@color/text_light"
android:gravity="left"
android:layout_width="0.0dip"
android:layout_height="wrap_content"
android:layout_marginLeft="3.0dip"
android:layout_weight="1.0"/>
android:id="@+id/layout_description_more"
android:paddingLeft="5.0dip"
android:layout_width="30.0dip"
android:layout_height="45.0dip">
android:layout_gravity="left|center"
android:layout_width="10.0dip"
android:layout_height="10.0dip"
android:src="@drawable/arrow"
/>
上面中最主要的就是LinearLayout的background, 这里说了点击的时候的背景是什么
xmlns:android="/apk/res/android">
//上面的
//color/lilayout_dark是在colors.xml中定义了的
#fff4f4f4
//color/layout_light
#ffffffff
OK 搞定, 这样点击的时候就会背景不一样了