1. layout中的相关代码:
<LinearLayout android:id="@+id/llGoodCommentContainer" android:orientation="vertical" android:layout_weight="1" android:gravity="center" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/layout_selector" android:clickable="true" > <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/zan" android:focusable="false" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="赞!" android:textColor="#ffffff" android:focusable="false" /> </LinearLayout>
2. drawable/文件夹下的layout_selecter.xml文件,这个文件就是设置点击時的颜色和默认显示時的颜色
<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_focused="true" android:drawable="@color/transparent_red"/> <item android:state_pressed="true" android:drawable="@color/transparent_red" /> <item android:drawable="@color/red"/> </selector>
3.color.xml文件中的两个颜色:
<color name="red">#ff5654</color> <color name="transparent_red">#ddff5654</color>
时间: 2024-11-06 15:01:09