示例:
<TextView android:id="@+id/tvNewDevice" android:layout_width="0dp" android:layout_height="38dp" android:layout_weight = "1" android:layout_marginTop="0dp" android:text="添加设备" android:textAlignment="center" android:gravity="center" android:textColor="@color/color_text_gray" android:textSize="@dimen/title_text_size" android:background="@drawable/tv_bg_selector" android:clickable="true" />
android:textAlignment="center" -- 水平居中
android:gravity="center" --垂直居中
android:background="@drawable/tv_bg_selector" --选中状态
android:clickable="true"
<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android" > <item android:state_pressed="true"> <shape android:shape="rectangle"> <solid android:color="#11000000"/> </shape> </item> <item android:state_pressed="false"> <shape android:shape="rectangle"> <!-- 透明色 --> <solid android:color="#00000000"/> </shape> </item> </selector>