A Material like circular avatar library for android. Generate first letter avatar Image like Google Contacts and random background.
-Add it in your root build.gradle at the end of repositories:
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
-Add the dependency
dependencies {
implementation 'com.github.RevelationCoding:Android-Avatar:Tag'
}
-Xml
<!--when random color is set true backgroundColor will be not set-->
<com.RevelationCoding.mylibrary.AndroidAvatar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
app:text="Name"
app:backgroundWidth="400"
app:backgroundHeight="400"
app:textSize="56"
app:imageSrc="@drawable/jordan"
app:randomColor="true"
app:backgroundColor="@color/dark"
app:textColor="@color/white" />
-Java
AndroidAvatarLib androidAvatarLib;
androidAvatarLib = findViewById(R.id.avatarBack_random);
//to set random color on click
androidAvatarLib.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
androidAvatarLib.setRandomColor();
}
});
-AndroidAvatarLib Available Methods
setChar(char c);
setTextSize(int size);
setRandomColor();
setBackColor(int color);
setTextColor(int color);
setBackgroundHeight(int height);
setBackgroundWidth(int width);
setText(String string);
setImageSrc(Drawable imageFile, int imageError, ImageView.ScaleType scaleType);
setImageUrl(String imageUrl, int imageError, ImageView.ScaleType scaleType);
Feel free to submit issues and enhancement requests. I'm very new to coding and git so I'm absolutely open to feedback and sugggestion. :)