Fiorella Artuso
Fiorella Artuso

Reputation: 31

How can i set a drawable in a CircleImageView (hdodenhof/CircleImageView)?

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {

   profilephoto.setImageDrawable(
       getResources().getDrawable(
           R.drawable.profile, 
           getApplicationContext().getTheme()));
} 
else {       
   profilephoto.setImageDrawable(
       getResources().getDrawable(
           R.drawable.profile));
}

I want to set an image into a circleImageView dynamically. I have used setImageDrawable, but the CircleImageView does not display any image.

Upvotes: 3

Views: 4734

Answers (2)

Axakalov Beksultan
Axakalov Beksultan

Reputation: 1

add this source code: setLayerType(View.LAYER_TYPE_SOFTWARE, null).

change code:

ImageView imageview = (ImageView) findViewById(R.id.profile_image);

To:

ImageView imageview = (ImageView) findViewById(R.id.profile_image);
imageView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);

Upvotes: 0

Sabbir Ahmed
Sabbir Ahmed

Reputation: 349

  1. add dependencies library in your gradle file

    compile 'de.hdodenhof:circleimageview:2.2.0'
    
  2. XML file

    < de.hdodenhof.circleimageview.CircleImageView
            xmlns:app="http://schemas.android.com/apk/res-auto"
            android:id="@+id/profile_image"
            android:layout_width="96dp"
            android:layout_height="96dp"
            app:civ_border_width="2dp"
            app:civ_border_color="#FF000000"/>
    
  3. Activity class

    ImageView imageView = (ImageView) findViewById(R.id.profile_image);
    imageView.setImageDrawable(getResources().getDrawable(R.drawable.sa));
    

Upvotes: 3

Related Questions