If use

val bitmap = MediaStore.Images.Media.getBitmap(contentResolver, selectedPhotoUri) val bitmapDrawable = BitmapDrawable(bitmap) select_button.setBackgroundDrawable(bitmapDrawable) 

Everything works fine (the button becomes a loaded image), but if you add a CircleImageView on top of the button and use the following code:

 val bitmap = MediaStore.Images.Media.getBitmap(contentResolver, selectedPhotoUri) profile_image.setImageBitmap(bitmap) profile_image.alpha = 0f 

That CircleImageView does not change (remains transparent).

xml:

  <de.hdodenhof.circleimageview.CircleImageView xmlns:app="http://schemas.android.com/apk/res-auto" android:id="@+id/profile_image" android:layout_width="150dp" android:layout_height="150dp" app:civ_border_width="2dp" app:civ_border_color="#FF000000" app:layout_constraintBottom_toBottomOf="@+id/select_button" app:layout_constraintEnd_toEndOf="@+id/select_button" app:layout_constraintTop_toTopOf="@+id/select_button" app:layout_constraintStart_toStartOf="@+id/select_button"/> </android.support.constraint.ConstraintLayout> 

How to make circleImageView take a bitmap value?

    1 answer 1

    The problem was that in my CircleImageView was under select_button and the button overlapped the image. To avoid this, add the line

     select_button.alpha = 0f 

    The button becomes transparent

    Summary Code:

     val bitmap = MediaStore.Images.Media.getBitmap(contentResolver, selectedPhotoUri) profile_image.setImageBitmap(bitmap) select_button.alpha = 0f