मैं एक साधारण चैट एप्लिकेशन कर रहा हूं और संदेश लिखते समय मैं संपादनों पर मुस्कुराहट दिखाना चाहता हूं।एडिटटेक्स्ट (स्माइलीज़) पर छविस्पैन। स्विफ्टकी कीबोर्ड के साथ काम नहीं करता
मैं इस जो पात्रों की पहचान के लिए एक ImageSpan सोचा एक छवि से subsituted हो जाएगा है (यह भी कहा जाता है केवल जब एक स्माइली चरित्र EditText पर डाला जाता है):
for (index = start; index < start+num_chars; index++) {
if (index + 1 > editable.length())
continue;
if(emoticons.containsKey(editable.subSequence(index, index + 1).toString())){
int length=1;
Drawable drawable = context.getResources().getDrawable(emoticons.get(editable.subSequence(index, index + 1).toString()));
Bitmap bitmap = ((BitmapDrawable) drawable).getBitmap();
int size=Utils.GetDipsFromPixel(context, (int)(textSize*1.3));
Drawable d = new BitmapDrawable(Bitmap.createScaledBitmap(bitmap, size, size, true));
int dWidth = d.getIntrinsicWidth();
int dHeight = d.getIntrinsicHeight();
d.setBounds(0 , -dHeight, dWidth, 0);
ImageSpan span;
span = new ImageSpan(d,ImageSpan.ALIGN_BASELINE);
editable.setSpan(span, index, index + length,Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
index += length - 1;
}
}
मैं SPAN_EXCLUSIVE_EXCLUSIVE टैग का उपयोग कर रहा स्थापित करने के लिए अवधि, लेकिन मुझे स्विफ्टकी कीबोर्ड के साथ समस्याएं हैं क्योंकि जब मैं संपादन में एक स्माइली डालता हूं, तो छवि के ठीक बाद मैं जो भी लिखता हूं, वह छवि के नीचे रहता है (जैसे SPAN_EXCLUSIVE_INCLUSIVE)। एंड्रॉइड डिफ़ॉल्ट कीबोर्ड के साथ मैं इस समस्या का सामना करता हूं।
मैं केवल एडिटटेक्स्ट पर व्हाट्सएप एप्लिकेशन वही व्यवहार श्वेत स्माइली चाहता हूं।
कोई सुझाव? मुझे अपने कोड में कोई बदलाव करना है?
संपादित करें: "संपादन योग्य" चर विधि को पास किया गया है। यह txtMessage.getText() मान है जहां txtMessage एक संपादन टेक्स्ट है।
धन्यवाद!
संपादित करें: केवल कोड का एक भाग फैलाएं! यह multiline में अच्छा काम करता है! मुझे लगता है कि समस्या Drawable-> बिटमैप-> ResizedBitmap-> Drawable का उपयोग करने में थी।
public static final HashMap<String, Integer> emoticons = new HashMap();
static {
emoticons.put("\ue415", R.drawable.e415);
emoticons.put("\ue056", R.drawable.e056);
emoticons.put("\ue057", R.drawable.e057);
...
public static Spannable getSmiledText(Context context, Spannable editable,
int start, int num_chars, float textSize) {
int index;
for (index = start; index < start + num_chars; index++) {
if (index + 1 > editable.length())
continue;
if (EmojiLayout.emoticons.containsKey(editable.subSequence(index,
index + 1).toString())) {
int length = 1;
Bitmap smiley = BitmapFactory.decodeResource(context.getResources(), ((Integer) EmojiLayout.emoticons.get(editable.subSequence(index,
index + 1).toString())));
int size = Utils.GetDipsFromPixel(context,
(int) (textSize * 1.37));
Bitmap scaledbmp=Bitmap.createScaledBitmap(
smiley, size, size, false);
ImageSpan span;
span = new ImageSpan(scaledbmp);
Log.d("EmojiLayout", "Index: " + String.valueOf(index) + "To: "
+ String.valueOf(index + length));
editable.setSpan(span, index, index + length,
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
index += length - 1;
}
}
return editable;
}
मेल डेवलपर को इस दोष और वे क्या कहते हैं .. – Ronnie