This is an Android library that will help users to have a circular TextView with an intial inside just like Gmail app with random colors that are genrated automatically. Please refer to included sample app for demo.
- First Add this to your root build.gradle file:
repositories {
maven { url 'https://jitpack.io' } //TODO
}
- Then to your project's build.gradle file:
dependencies {
.......
compile 'com.github.aamirwahid5:CircleTextView:1.0' //TODO
}
Or Maven: First this in your root build.gradle:
repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
then add the dependency in your project's build.gradle:
<dependency>
<groupId>com.github.aamirwahid5</groupId>
<artifactId>CircleTextView</artifactId>
<version>1.0</version>
</dependency>
This goes in your layout xml file with width and height as u want:
<project.aamir.sheikh.circletextview.CircleTextView
android:id="@+id/ctv"
android:layout_width="50dp"
android:layout_height="50dp"
android:gravity="center" />
and then in your java file:
CircleTextView mCircleTextView = (CircleTextView) findViewById(R.id.ctv); //change with your id
mCircleTextView.setCustomText(mArrayList.get(position)); //Supply your whole text here it will automatically generate the initial
mCircleTextView.setSolidColor(position); //pass position if used inside RecyclerView otherwise you can keep blank this is used to save background color state
mCircleTextView.setTextColor(Color.WHITE);
mCircleTextView.setCustomTextSize(18); //change with your text size or if not used will take size automatically