2011-06-30 6 views

Trả lời

9

tạo ra một selector (nó là một tập tin xml) đặt trong thư mục drawable. và trong xml lăm con đường của xml mà instaed của hình ảnh thực tế android:background="@drawable/imageselector" hoặc trong chương trình bạn cũng có thể nhận được cùng sử dụng imageview.setBackgroundDrawable(R.drawable.imageselector)

Sau đây là selector tôi imageselector.xml

<?xml version="1.0" encoding="utf-8"?> 
<selector 
    xmlns:android="http://schemas.android.com/apk/res/android"> 
    <item 
     android:state_focused="true" 
     android:state_pressed="false" 
     android:drawable="@drawable/arow_selected" /> 
    <item 
     android:state_focused="true" 
     android:state_pressed="true" 
     android:drawable="@drawable/arow_selected" /> 
    <item 
     android:state_focused="false" 
     android:state_pressed="true" 
     android:drawable="@drawable/arow_selected" /> 
    <item 
     android:drawable="@drawable/arow_unselect" /> 
</selector> 
0

Bạn có thể sử dụng hình ảnh Xem cho cùng:

<ImageView 
      android:id="@+id/iv1" 
      android:src="@drawable/ic_new_delete0" 
      android:layout_width="wrap_content" 
      android:layout_height="40dp" 
      android:visibility="visible" /> 

Mã đằng sau:

ImageView _iv1 = _activity.FindViewById<ImageView>(Resource.Id.iv1); 

     _iv1.Touch += (object sender, View.TouchEventArgs e) => { 
      if (e.Event.Action == MotionEventActions.Down) 
      { 
       _iv1.SetImageResource(Resource.Drawable.ic_new_delete); 
       //Do the task when button is pressed 
      } 
      else if (e.Event.Action == MotionEventActions.Up) 
      { 
       _iv1.SetImageResource(Resource.Drawable.ic_new_delete0); 
       //do the task when button is released 
      } 
     };