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

不帶富文本格式的粘貼到 EditText

Paste without rich text formatting into EditText(不帶富文本格式的粘貼到 EditText)
本文介紹了不帶富文本格式的粘貼到 EditText的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

限時送ChatGPT賬號..

如果我從 Chrome for Android 復制/粘貼文本到我的 EditText 視圖中,它會變得一團糟,顯然是由于富文本格式.

If I copy/paste text from Chrome for Android into my EditText view it gets messed up, apparently due to rich text formatting.

有沒有辦法告訴 Edi??tText 視圖忽略富文本格式?或者我可以在粘貼事件設置之前將其刪除嗎?我該怎么做?

Is there a way to tell the EditText view to ignore rich text formatting? Or can I catch the paste event and remove it before it gets set? How would I do that?

更新:所以我意識到 editText.getText() 給了我一個 SpannableString 包含一些格式.我可以通過調用 .clearSpans(); 來擺脫它.但是我不能在 editText.addTextChangedListener(new TextWatcher() { ... } 中做類似的事情,因為它變得非常慢,并且 UI 僅在我離開 editText 視圖時更新.

UPDATE: So I realized that the editText.getText() gives me a SpannableString that contains some formatting. I can get rid of that by calling .clearSpans(); on it. BUT I cannot do anything like that in editText.addTextChangedListener(new TextWatcher() { … } because it gets terribly slow and the UI only updates when I leave the editText view.

推薦答案

clearSpans() 的問題是它刪除了太多,并且此后editText 的行為很奇怪.通過遵循 this answer 中的方法,我只刪除了 MetricAffectingSpan 和那么它工作正常.

The problem with clearSpans() was that it removed too much and the editText behaves weird thereafter. By following the approach in this answer I only remove the MetricAffectingSpan and it works fine then.

對我來說,唯一的問題是文本的大小.如果您有其他問題,則必須調整要刪除的內容.

For me the only problem was the size of the text. If you have other problems you'd have to adjust what you want to remove.

public void afterTextChanged(Editable string)
{
    CharacterStyle[] toBeRemovedSpans = string.getSpans(0, string.length(),
                                                MetricAffectingSpan.class);
    for (int index = 0; index < toBeRemovedSpans.length; index++)
        string.removeSpan(toBeRemovedSpans[index]);
    }
}

這篇關于不帶富文本格式的粘貼到 EditText的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

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

相關文檔推薦

Cut, copy, paste in android(在android中剪切、復制、粘貼)
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 位小數的數字)
Changing where cursor starts in an expanded EditText(更改光標在展開的 EditText 中的開始位置)
EditText, adjustPan, ScrollView issue in android(android中的EditText,adjustPan,ScrollView問題)
主站蜘蛛池模板: 精品成人在线 | 91免费视频观看 | 羞羞网站在线免费观看 | 久久一二区 | www.99热.com | 中文字幕精品一区 | 国产精品久久国产愉拍 | 国产精品久久久久久久久久久久 | 99免费| 国产一区二区三区在线免费观看 | 欧美在线色视频 | 成人免费视频一区 | 国产精品视频一区二区三区四蜜臂 | 久久综合一区 | 久久成人一区 | 久久99精品久久久久子伦 | 久久国产欧美日韩精品 | 最新中文字幕在线 | 成人黄色在线 | 91在线观看视频 | 一级黄色av电影 | 先锋资源吧 | 日韩av资源站 | 91精品久久久久久久久中文字幕 | 九九久久久 | 91免费看片 | 久久99视频这里只有精品 | 欧美日韩国产传媒 | av在线影院 | 99精品一区 | 国产日韩一区二区三区 | 欧美二区三区 | 在线日韩欧美 | 国产高清精品一区二区三区 | 成人高清视频在线观看 | 一级黄色片一级黄色片 | 午夜精品久久久久久久星辰影院 | 精品中文字幕一区 | 国产精品久久亚洲7777 | 在线视频日韩精品 | 免费观看黄a一级视频 |