使用颜色做点击效果selector

以设置的按钮为例:

点击效果文件selector_setting.xml

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@color/white" android:state_pressed="false"/>
    <item android:drawable="@color/setting_item_press_bg" android:state_pressed="true"/>
</selector>

这里drawable直接使用自定义颜色来做colors.xml:

	<color name="white">#FFFFFF</color>
    <color name="setting_item_press_bg">#F0F0F0</color>

部局文件的一部分:setting.xml

扫描二维码关注公众号,回复: 591797 查看本文章
<LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="20dp"
                    android:background="#ffff"
                    android:orientation="vertical" >

                    <ImageView
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:src="@drawable/line" />

                    <!-- 意见反馈 -->

                    <RelativeLayout
                        android:id="@+id/set_commit"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:orientation="horizontal"
                        android:padding="12dp"
                        android:background="@drawable/selector_setting"
                         >

                        <TextView
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:text="@string/set_feedback"
                            android:textColor="#000" />

                        <ImageView
                            android:layout_width="15dp"
                            android:layout_height="15dp"
                            android:layout_alignParentRight="true"
                            android:src="@drawable/arrow" />
                    </RelativeLayout>

                    <ImageView
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_marginLeft="12dp"
                        android:src="@drawable/line" />

                    <!-- 版本更新 -->

                    <RelativeLayout
                        android:id="@+id/set_ver_update"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:orientation="horizontal"
                        android:background="@drawable/selector_setting"
                        android:padding="12dp" >

                        <TextView
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:text="@string/set_version_update"
                            android:textColor="#000" />

                        <ImageView
                            android:layout_width="15dp"
                            android:layout_height="15dp"
                            android:layout_alignParentRight="true"
                            android:src="@drawable/arrow" />
                    </RelativeLayout>

                    <ImageView
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_marginLeft="12dp"
                        android:src="@drawable/line" />

                    <!-- 关于我们 -->

                    <RelativeLayout
                        android:id="@+id/set_about"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:orientation="horizontal"
                        android:background="@drawable/selector_setting"
                        android:padding="12dp" >

                        <TextView
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:text="@string/set_about_us"
                            android:textColor="#000" />

                        <ImageView
                            android:layout_width="15dp"
                            android:layout_height="15dp"
                            android:layout_alignParentRight="true"
                            android:src="@drawable/arrow" />
                    </RelativeLayout>

                    <ImageView
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_marginLeft="12dp"
                        android:src="@drawable/line" />

                    <!-- 给我评分 -->
                    <!--
                     <RelativeLayout                 
                    android:layout_width="match_parent"
                	android:layout_height="wrap_content"
                	android:orientation="horizontal"
                	android:padding="12dp"
                	>
                	
                	<TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="给我评分"
                        android:textColor="#000" />
                	
                	<ImageView 
					   	android:layout_width="15dp"
					    android:layout_height="15dp"
					    android:src="@drawable/arrow"
					    android:layout_alignParentRight="true"
					    />
                </RelativeLayout>
                
                <ImageView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="12dp"
                    android:src="@drawable/line" />
                    -->


                    <!-- 修改密码 -->

                    <RelativeLayout
                        android:id="@+id/set_edit_password"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:orientation="horizontal"
                        android:background="@drawable/selector_setting"
                        android:padding="12dp" >

                        <TextView
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:text="@string/set_modify_pass"
                            android:textColor="#000" />

                        <ImageView
                            android:layout_width="15dp"
                            android:layout_height="15dp"
                            android:layout_alignParentRight="true"
                            android:src="@drawable/arrow" />
                    </RelativeLayout>

                    <ImageView
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_marginLeft="12dp"
                        android:src="@drawable/line" />

                    <!-- 应用推荐 -->

                    <RelativeLayout
                        android:id="@+id/set_app_center"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:orientation="horizontal"
                        android:background="@drawable/selector_setting"
                        android:padding="12dp" >
                        
                        <TextView
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:text="@string/set_app_center"
                            android:textColor="#000" />

                        <ImageView
                            android:layout_width="15dp"
                            android:layout_height="15dp"
                            android:layout_alignParentRight="true"
                            android:src="@drawable/arrow" />
                    </RelativeLayout>

                    <ImageView
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:src="@drawable/line" />
                </LinearLayout>

猜你喜欢

转载自hz-chenwenbiao-91.iteye.com/blog/2038887