I am using only one text view and using spanable to add fonts and color to strings. But i am getting problem to display rounded background to string using spanable. So How can I achieve this using spannable String concept the image is as shown below.
For the background color of your TextView
you can use
String myString = "myString";
Spannable spanna = new SpannableString(myString);
spanna.setSpan(new BackgroundColorSpan(0xFFCCCCCC),0, myString.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
myTextView.setText(spanna);
and for rounded text-view create your custom XML and set background to that textview.
Edit
Create one XML called rounded_corner.xml and set this content
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<!-- view background color -->
<solid android:color="#ffffff" >
</solid>
<!-- view border color and width -->
<stroke
android:width="1dp"
android:color="#1c1b20" >
</stroke>
<!-- If you want to add some padding -->
<padding
android:bottom="4dp"
android:left="4dp"
android:right="4dp"
android:top="4dp" >
</padding>
<!-- Here is the corner radius -->
<corners android:radius="10dp" >
</corners>
</shape>
and then add this line to your textview in XML
android:background="@drawable/rounded_corner"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With