2013-07-09 2 views
1

부모 선형 레이아웃을 클릭하면 버튼의 텍스트 색상을 변경하고 이미지를 수정하고 싶습니다. 이미지가 변경되지만 선형 레이아웃을 클릭하면 텍스트 색상이 변경되지 않습니다.부모 LinearLayout의 onclick 버튼의 TextColor가 변경되지 않습니다.

<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> 

내가 텍스트 뷰와 버튼을 교체하는 경우, 모든 것이 잘 작동 -

다음은 XML 내 코드입니다. 이 라인에서

답변

0

솔루션을 찾았습니다. 완료 버튼에 대해 false로 clickable을 설정해야합니다. 이제는 부모 onClick 이벤트도 인식합니다.

왜 위 코드는 onClick 이벤트가 byDefault를 사용하지 않으므로 textView에서 작동하므로 부모 onClick 이벤트를 인식합니다.

1

는 :

<item android:state_focused="true" android:color="@color/done_btn_pressed_color" /> 
    <item android:state_pressed="true" android:color="@color/done_btn_pressed_color" /> 

당신은 같은 색상 done_btn_pressed_color을 넣어. 아마도 문제일까요?

+0

아니요. 문제가되지 않습니다. 기본 색상이 다릅니다. – Sunita

+0

코드에서 변경하려고 할 수 있습니다. – dasdasd

+0

시도했습니다. button [textcolor 변경] 및 imageview [change image]에 대해 두 개의 다른 XML 선택기가 있으므로 선형 레이아웃으로 설정할 수 없습니다. 단추 레이아웃을 변경하면 도움이되지 않습니다. – Sunita

관련 문제