我想改變按鈕的文本顏色和修改圖像,當我點擊其父線性佈局。 圖像正在改變,但textcolor不會在線性佈局點擊時發生變化。TextColor的按鈕不會改變onLight的父LinearLayout
這是我在XML碼 -
<LinearLayout
android:id="@+id/btn_layout"
android:layout_width="0.0dip"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1.0"
android:gravity="center"
android:clickable="true"
android:orientation="horizontal" >
<Button
android:id="@+id/done"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:text="@string/done_with_accounts_action"
android:textColor="@drawable/done_button_text_selector"
android:focusable="false"
android:textSize="@dimen/done_button_text_size" />
<ImageView
android:id="@+id/done_btn_arrow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:paddingLeft="4dp"
android:focusable="false"
android:src="@drawable/done_btn_arrow_bg_selector" />
</LinearLayout>
**selector xml for button -**
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_focused="true" android:color="@color/done_btn_pressed_color" />
<item android:state_pressed="true" android:color="@color/done_btn_pressed_color" />
<item android:color="@color/button_text_white_color" />
</selector>
如果我的TextView更換按鈕,一切工作正常。
不,這不是問題。默認顏色是不同的。 – Sunita
您可以嘗試從代碼中進行更改。 – dasdasd
我試過了。我不能將它設置爲線性佈局,因爲按鈕[change textcolor]和imageview [change image]有兩個不同的xml選擇器,並且按鈕佈局上的更改不起作用。 – Sunita