skip to Main Content

I have a plain white background with a few clouds on it. When the user clicks an object on screen the white part of the background image changes color. The clouds remain untouched by the color change.

Until now I had been making each individual backgroud image in photoshop and loading them into the onclick method. But now I’m wondering is it possible to have just one background image and when the user clicks an object android can change the background color of the image using the predefined colors.xml file?

3

Answers


  1. Have an image for cloud and make the background color for your layout to White color. When the user clicks object have a listener on the view to listen click and change the color of layout dynamically.

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@drawable/YourPicture"
        android:id=@+id/root_layout>
     <-- your Views-->
     </LinearLayout>
    

    Your Activity file:

    yourView.setOnClickListener(v -> {
     rootLayout.setBackground(ContextCompat.getDrawable(context, R.drawable.draw));
     });
    
    Login or Signup to reply.
  2. It’s depends how did you draw the image. If the background you want to change is transparent you can do:

    imageView.setBackgroundColor(color)
    
    Login or Signup to reply.
  3. No, I don’t think so it is possible.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search