Reputation: 2731
I have a imageButton in android which user clicks. Then after his click I want t0 show a tick or a cross image on the toip of it. How is it possible?
<ImageButton android:layout_width="wrap_content"
android:text="Button" android:id="@+id/button1"
android:layout_height="wrap_content" android:layout_gravity="center_horizontal"
android:background="@drawable/rhino" android:layout_marginRight="20dp"></ImageButton>
Upvotes: 2
Views: 3279
Reputation: 53647
You can achieve the same using ImageView. Use ImageView
testimage = (ImageView) findViewById(R.id.imageview);
testimage.setOnClickListener(listener);
write the logic to set both type of image to imageview in onclick event
public OnClickListener listener=new OnClickListener(){
@Override
public void onClick(View arg0) {
System.out.println("..set image button..");
Drawable[] layers = new Drawable[2];
layers[0] = getResources().getDrawable(R.drawable.btn_call);
layers[1] = getResources().getDrawable(R.drawable.blue_unfocus);
System.out.println(layers[1]+"...Drawable..."+layers[0]);
LayerDrawable layerDrawable = new LayerDrawable(layers);
testimage.setImageDrawable(layerDrawable);
}
};
Thanks Deepak
Upvotes: 0
Reputation: 10622
put your ImageButton and the tick image in a FrameLayout and make the visbility of the Tick image "Invisible" . So when you click on the ImageButton then change the state of Tick Image to Visible.
Upvotes: 3
Reputation: 2045
Get a reference to your ImageButton and then use one of its setImage methods, such as setImageResource.
Upvotes: 0