2011-06-30 12 views

Odpowiedz

9

stworzyć selektor (jest to plik XML) umieścić w rozciągliwej folderu. aw xml pięć ścieżka tego xml instaed od rzeczywistego obrazu android:background="@drawable/imageselector" lub w programie również można dostać to samo za pomocą imageview.setBackgroundDrawable(R.drawable.imageselector)

Poniżej mój selektor 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

Można użyć obrazu View dla tego samego:

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

Kod za:

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 
      } 
     }; 
Powiązane problemy