How To Change The Imagebutton's Image When It Is Pressed And Released?
I want that in my android application, the ImageButton change its image when it is pressed and released, and when it is pressed released again, the image for ImageButton will be ch
Solution 1:
create a selector (it is an xml file) put in drawable folder. and in xml five path of that xml instaed of actual image android:background="@drawable/imageselector"
or in program also you can get the same using imageview.setBackgroundDrawable(R.drawable.imageselector)
Following is my selector imageselector.xml
<?xml version="1.0" encoding="utf-8"?><selectorxmlns:android="http://schemas.android.com/apk/res/android"><itemandroid:state_focused="true"android:state_pressed="false"android:drawable="@drawable/arow_selected" /><itemandroid:state_focused="true"android:state_pressed="true"android:drawable="@drawable/arow_selected" /><itemandroid:state_focused="false"android:state_pressed="true"android:drawable="@drawable/arow_selected" /><itemandroid:drawable="@drawable/arow_unselect" /></selector>
Solution 2:
use selector for this...here is a link for this.. http://developer.android.com/reference/android/widget/ImageButton.html
Solution 3:
You can use Image View for the same:
<ImageView
android:id="@+id/iv1"
android:src="@drawable/ic_new_delete0"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:visibility="visible" />
Code behind:
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
}
elseif (e.Event.Action == MotionEventActions.Up)
{
_iv1.SetImageResource(Resource.Drawable.ic_new_delete0);
//do the task when button is released
}
};
Post a Comment for "How To Change The Imagebutton's Image When It Is Pressed And Released?"