Reputation: 31
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
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
Reputation: 349
add dependencies library in your gradle file
compile 'de.hdodenhof:circleimageview:2.2.0'
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"/>
Activity class
ImageView imageView = (ImageView) findViewById(R.id.profile_image);
imageView.setImageDrawable(getResources().getDrawable(R.drawable.sa));
Upvotes: 3