I want to create a circular color filled drawable with a letter inside it in android java. I want to set the letter and color dynamically. Any ideas how to create it?
Asked
Active
Viewed 80 times
2 Answers
0
Try this.https://github.com/amulyakhare/TextDrawable in this repository you can put text in a drawable

Shailendra Kushwah
- 415
- 1
- 6
- 17
0
Create your TextView like this (this one centers the text):
<TextView
android:id="@+id/mTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_centerVertical="true"
android:background="@drawable/shape_circle">
</TextView>
Your shape like this:
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<solid
android:color="@color/circleColor">
</solid>
<size
android:width="@dimen/circleSize"
android:height="@dimen/circleSize"
/>
</shape>
Then you can set the text in the TextView dynamically as usual with mTextView.setText().
To change the color dynamically, take a look here.