I got stuck in this problem since yesterday. I am using spannable string
and want to add custom shape to it similar to chips:
Here is my code where I am modifying the spannable
string:
s.setSpan(new BackgroundColorSpan(backgroundColor), currentIndex, currentIndex + words[i].length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
I tried with Bitmap
but according to process I need to convert my Editable
with BitmapDrawable
as per the code:
BitmapDrawable bd = (BitmapDrawable) convertViewToDrawable(textView);
The problem I am facing is that I am not using textView
. I am working on AutoCompleteTextView
and converting AutoCompleteTextView
to Bitmap
is impossible (If I am not wrong here).
How can I achieve the similar result?
Edit-1
I used following shape
:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<stroke android:width="1dp" android:color="#A6B0B8" />
<gradient android:startColor="#E5E5E6"
android:endColor="#B4B6B7"
android:angle="-270"/>
<corners android:bottomRightRadius="10dp"
android:bottomLeftRadius="10dp"
android:topLeftRadius="10dp"
android:topRightRadius="10dp"></corners>
</shape>
Custom Drawable
public class CustomDrawble extends DynamicDrawableSpan {
private Context mContext;
CustomDrawble(Context context){
super();
this.mContext = context;
}
@Override
public Drawable getDrawable() {
Resources res = mContext.getResources();
Drawable drawable = res.getDrawable(R.drawable.bubble);
drawable.setBounds(0,0,100,20);
return drawable;
}
}
For applying above Drawable
I used following code:
s.setSpan(new CustomDrawble(mContext), currentIndex, currentIndex + words[i].length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
From the #Edit-1 section I am getting this:
What I am doing wrong here? I am using Widget.SearchView
not a TextView