Advertisement
Guest User

Untitled

a guest
Jul 6th, 2015
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.82 KB | None | 0 0
  1. final ImageView like = (ImageView) findViewById(R.id.like);
  2.  
  3. //set the click listener
  4. like.setOnClickListener(new OnClickListener() {
  5.  
  6. public void onClick(View button) {
  7. //Set the button's appearance
  8. button.setSelected(!button.isSelected());
  9.  
  10. if (button.isSelected()) {
  11. like.setBackgroundDrawable(null);
  12. like.setBackgroundResource(R.drawable.starf);
  13.  
  14. } else {
  15. like.setBackgroundResource(R.drawable.star);
  16. }
  17. }
  18. });
  19.  
  20. <ImageView
  21. android:id="@+id/like"
  22. android:layout_width="wrap_content"
  23. android:layout_height="fill_parent"
  24. android:layout_gravity="left"
  25. android:paddingLeft="10dp"
  26. android:paddingRight="40dp"
  27. android:background="@drawable/star"
  28. android:clickable="true" />
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement