2012-06-23 26 views
0

我有兩個TextViews裏面的相對佈局。 當RelativeLayout被按下時,我如何改變文本顏色TextViews?如何在Android中捕獲RelativeLayout按下的狀態?

我試過使用選擇器,但相對佈局不支持文本顏色屬性。

此外,嘗試捕獲與OnFocus和OnTouch偵聽器的相對佈局按下狀態,但他們不工作(OnFocusChangeListener)或工作在一側(OnTouchListener)。

代碼:

<RelativeLayout 
     android:layout_width="fill_parent" 
     android:layout_height="243dp" 
     android:layout_alignParentBottom="true" 
     android:layout_alignParentLeft="true" 
     android:background="@drawable/singup_button_selector" 
     android:clickable="true" 
     android:focusable="true" 
     android:gravity="center" 
     android:id="@+id/sungup" 
     android:textColor="@drawable/singup_button_text_selector" 
     android:focusableInTouchMode="true"> 

     <TextView 
      android:id="@+id/singupTV1" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentTop="true" 
      android:layout_centerHorizontal="true" 
      android:text="@string/singup" 
      android:textColor="#3c5775"/> 




     <TextView 
      android:id="@+id/singupTV2" 
      android:layout_width="300dp" 
      android:layout_height="wrap_content" 
      android:layout_below="@+id/singupTV1" 
      android:layout_marginTop="15dp" 
      android:gravity="center" 
      android:text="@string/singup_extended" 
      android:textColor="#506378" 
      android:textSize="15dp" /> 

    </RelativeLayout> 

回答

0

您可以在RelativeLayout的設置onClickListener,然後在onclick方法,改變在這兩個TextViews文本顏色在你的代碼。

+0

不是一種方式,因爲它只在鬆開手指後才起作用。 – bvitaliyg

+0

當我鬆開手指時,它必須從手指觸摸開始並停止。 – bvitaliyg

0

對我而言有效的是設置了OnTouchListener

setOnTouchListener(new OnTouchListener() { 
    @Override 
    public boolean onTouch(View v, MotionEvent event) 
    { 
     if(event.getAction() == MotionEvent.ACTION_DOWN || event.getAction() == MotionEvent.ACTION_MOVE) { 
      // focus in 
     } else{ 
      // focus out 
     } 

     return false; 
    } 
}); 
相關問題