久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

如何將圖像插入editText

how to insert image to a editText(如何將圖像插入editText)
本文介紹了如何將圖像插入editText的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

限時送ChatGPT賬號..

我想將圖像插入到 editText 我的代碼是:

I want to insert a image to a editText my code is:

  CharSequence charSeq= editText.getText()+" ";
  SpannableString ss2 = new SpannableString(charSeq); 
  Drawable d2 = holder.image.getDrawable(); 
  d2.setBounds(0, 0, d2.getIntrinsicWidth(), d2.getIntrinsicHeight()); 

  ImageSpan span2 = new ImageSpan(d2, ImageSpan.ALIGN_BASELINE); 
  ss2.setSpan(span2,charSeq.length()-1, charSeq.length(),  

  Spannable.SPAN_INCLUSIVE_INCLUSIVE); 

  editText.setText(ss2,BufferType.SPANNABLE); 

我的代碼可以運行,但我有一些不錯的經(jīng)驗我想修改:

My code can run but i have some not bad experience i want to modify:

1:你知道當(dāng)使用ss2.setSpan()方法時,圖片可以替換字符,我只想插入新圖片,不想圖片替換字符.

1: You know when use ss2.setSpan() method, the image can replace the character, i only want to insert new image, donot want to the image replace the character.

2:你知道我的方法包括editText.getText()+";",我添加了一些額外的空間,以便圖像可以插入到 CharSequence 的最后.怎么不用添加一些Extra,圖片也插入到CharSequence的最后.

2: you know my method include "editText.getText()+" ";", i add some Extra space, so that the image can insert to the last of the CharSequence. how to not need add add some Extra, the image also insert to the last of the CharSequence.

3.當(dāng)我將圖像插入到 CharSequence 的最后時,光標(biāo)不在最后,它出現(xiàn)在 CharSequence 的前面.如何將光標(biāo)放在圖像的后面.

3.when i insert the image to the last of the CharSequence, the cursor not at the last, it appear in the front of the CharSequence. how to put the cursor at the behind the image.

4.我想不斷的在不同的CharSequence中插入圖片,怎么辦?

4.i want to constantly insert the image in the different of the CharSequence,how to do?

我的問題太多了,希望你能幫助我,非常感謝.

My question so many, I want you can help me thank you very very much.

推薦答案

做這樣的事情(注意:可以復(fù)用 SpannableStringBuilder)

Do something like this (note: you can reuse SpannableStringBuilder)

editText = (EditText)mRoot.findViewById(R.id.content);
ImageSpan imageSpan = new ImageSpan(preview);

SpannableStringBuilder builder = new SpannableStringBuilder();
builder.append(editText.getText());

// this is a string that will let you find a place, where the ImageSpan is.
String imgId = "[img=1]"; 

int selStart = editText.getSelectionStart();

// current selection is replaceв with imageId
builder.replace(editText.getSelectionStart(), editText.getSelectionEnd(), imgId);

// This adds a span to display image where the imageId is. If you do builder.toString() - the string will contain imageId where the imageSpan is.
// you can use it later - if you want to find location of imageSpan in text;
builder.setSpan(imageSpan, selStart, selStart + imgId.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
editText.setText(builder);

注意:請參閱后續(xù)回答處理部分刪除標(biāo)簽

Note: See follow up answer for dealing with partial deletion of tags

這篇關(guān)于如何將圖像插入editText的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

Cut, copy, paste in android(在android中剪切、復(fù)制、粘貼)
android EditText blends into background(android EditText 融入背景)
Change Line Color of EditText - Android(更改 EditText 的線條顏色 - Android)
EditText showing numbers with 2 decimals at all times(EditText 始終顯示帶 2 位小數(shù)的數(shù)字)
Changing where cursor starts in an expanded EditText(更改光標(biāo)在展開的 EditText 中的開始位置)
EditText, adjustPan, ScrollView issue in android(android中的EditText,adjustPan,ScrollView問題)
主站蜘蛛池模板: 国产精品久久久久久影院8一贰佰 | 亚洲欧洲精品在线 | 国产日韩中文字幕 | 国产精品综合 | 中文字幕不卡在线观看 | 亚州综合在线 | 伊人青青久久 | 亚洲成av人片在线观看无码 | 欧美伊人久久久久久久久影院 | 久久久久国产一区二区三区 | 中文字幕av一区 | 免费一二区 | www国产精品| 欧美国产日韩在线观看 | 韩日一区二区 | 青娱乐国产| 国产在线播放av | 中文字幕免费在线观看 | 在线播放中文字幕 | 欧美日韩亚洲三区 | 中文字幕一级毛片 | 91精品一区 | 久久久久久国产精品mv | 亚洲精品在线免费 | 日韩欧美三区 | 亚洲天堂网站 | 国产视频久久 | 午夜99| 91精品亚洲| 91资源在线观看 | 亚洲自拍偷拍欧美 | 青青草精品视频 | 色婷婷久久久久swag精品 | 欧美精品综合 | 性生生活大片免费看视频 | 亚洲视频一区二区三区 | 男女羞羞视频在线观看 | 中文在线视频 | 男女午夜免费视频 | 久在线 | 日韩国产欧美视频 |