2010-12-03 2 views
0

아래 코드를 사용하여 안내 해주세요. 내 문제는 입니다. TextView의 "눌림"상태가 표시되지 않습니다. 구현할 수 있습니까? TextView의 눌림 상태? 내가 어떻게 할?안드로이드 - TextView 백그라운드 색상이 다른 상태로 변경되었습니다.

다음 코드를 사용하여 성공했지만 TextView에 성공하지 못했습니다.

pls는 저에게 안내

내 버튼 및 텍스트 뷰 코드 :

<Button 
    android:id="@+id/Button01" 
    android:layout_width="fill_parent" 
    android:layout_height="50dp" 
    android:background="@drawable/button_state" 
    android:padding="20dp"> 
</Button> 

<TextView 
    android:text="Demo of Color on state change" 
    android:id="@+id/TextView01" 
    android:layout_width="fill_parent" 
    android:layout_height="50dp" 
    android:background="@drawable/button_state" 
    android:focusable="true"> 
</TextView> 

button_state.xml 파일 (내가 당김 폴더에 저장 한) :

<selector 
    xmlns:android="http://schemas.android.com/apk/res/android"> 

    <item android:state_pressed="true"> 
     <shape> 
      <gradient 
       android:startColor="@color/yellow1" 
       android:endColor="@color/yellow2" 
       android:angle="270" /> 
      <stroke 
       android:width="3dp" 
       android:color="@color/grey" /> 
      <corners 
       android:radius="3dp" /> 
      <padding 
       android:left="10dp" 
       android:top="10dp" 
       android:right="10dp" 
       android:bottom="10dp" /> 
     </shape> 
    </item> 

    <item android:state_focused="true" > 
     <shape> 
      <gradient 
       android:endColor="@color/orange1" 
       android:startColor="@color/orange2" 
       android:angle="270" /> 
      <stroke 
       android:width="3dp" 
       android:color="@color/grey" /> 
      <corners 
       android:radius="3dp" /> 
      <padding 
       android:left="10dp" 
       android:top="10dp" 
       android:right="10dp" 
       android:bottom="10dp" /> 
     </shape> 
    </item> 

    <item>   
     <shape> 
      <gradient 
       android:endColor="@color/blue1" 
       android:startColor="@color/blue2" 
       android:angle="270" /> 
      <stroke 
       android:width="3dp" 
       android:color="@color/grey" /> 
      <corners 
       android:radius="3dp" /> 
      <padding 
       android:left="10dp" 
       android:top="10dp" 
       android:right="10dp" 
       android:bottom="10dp" /> 
     </shape> 
    </item> 
</selector> 

color.xml 파일 :

<resources> 
<color name="yellow1">#FFFF99</color> 
<color name="yellow2">#FFCC00</color> 
<color name="orange1">#FF9966</color> 
<color name="orange2">#FF6600</color> 
<color name="blue1">#99CCFF</color> 
<color name="blue2">#0033CC</color> 
<color name="grey">#736F6E</color> 
</resources> 
+1

나는 동일한 주제로 SO에 대한 질문을했지만 유용하지는 않습니다. http://stackoverflow.com/questions/4336218/android-textview-change-color-on-changing-of-state –

답변

4

AFAIK, TextView은 눌린 상태를 지원하지 않습니다.

그냥 Button을 사용하십시오. Button 배경을 변경하고 있으므로 TextView과 같은 모양을 포함하여 원하는 모양으로 만들 수 있습니다.

+0

어떻게 TextView처럼 보이도록 단추를 스타일링합니까?