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

如何在 EditText 中以不同顏色標(biāo)記值?

How to hashtag value in different colour in EditText?(如何在 EditText 中以不同顏色標(biāo)記值?)
本文介紹了如何在 EditText 中以不同顏色標(biāo)記值?的處理方法,對(duì)大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

限時(shí)送ChatGPT賬號(hào)..

當(dāng)我寫 "#data" 時(shí),我在 EditText 中寫了一些文本,它的顏色應(yīng)該改變但不會(huì)改變我該怎么做.請(qǐng)檢查以下我使用過的EditText

I am writing some text in EditText when i write "#data" its colour should be changed but doesn't change how can i do. Please check the below EditText which i have used

<EditText
         android:id="@+id/et_simple"
         android:layout_height="wrap_content"
         android:layout_width="match_parent">
</EditText>

推薦答案

希望這個(gè)解決方案會(huì)有所幫助..!

Hope this solution will help..!

我使用了這個(gè)解決方案,非常有用!就像在你的 editText 上添加 textWatcher 接口并收聽 textChange 并找出單詞是否以 hashTag 開頭然后調(diào)用該單詞的 Change The color 方法!它有一些缺陷,但這些都是可以忽略不計(jì)的,請(qǐng)看這個(gè)簡(jiǎn)單的.

I used this solution it is very useful! like adding the textWatcher interface over your editText and listening to textChange and finding out if the word starts with a hashTag then call the Change The color method on that word! it has some flaws but those are ignorable see this simple one here.

Spannable mspanable;
int hashTagIsComing = 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);



    final EditText edtTxtMine = (EditText) findViewById(R.id.editText1);

    mspanable = edtTxtMine.getText();

    edtTxtMine.addTextChangedListener(new TextWatcher() {

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {

            String startChar = null;

            try{
                startChar = Character.toString(s.charAt(start));
                Log.i(getClass().getSimpleName(), "CHARACTER OF NEW WORD: " + startChar);
            }
            catch(Exception ex){
                startChar = "";
            }

                if (startChar.equals("#")) {
                     changeTheColor(s.toString().substring(start), start, start + count);
                     hashTagIsComing++;
                }

                if(startChar.equals(" ")){
                    hashTagIsComing = 0;
                }

                if(hashTagIsComing != 0) {
                    changeTheColor(s.toString().substring(start), start, start + count);
                    hashTagIsComing++;
                }
        }

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count,
                int after) {
            // TODO Auto-generated method stub

        }

        @Override
        public void afterTextChanged(Editable s) {
            // TODO Auto-generated method stub

        }
    });



}


private void changeTheColor(String s, int start, int end) {
    mspanable.setSpan(new ForegroundColorSpan(getResources().getColor(R.color.color)), start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}

這篇關(guān)于如何在 EditText 中以不同顏色標(biāo)記值?的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(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問題)
主站蜘蛛池模板: 美女无遮挡网站 | 国产性hd | 午夜网址 | www.17c.com喷水少妇 | 国产一区二区欧美 | 亚洲精品免费看 | 啊v在线观看 | 国产精品高潮呻吟av | 波多野结衣一区二区三区 | 欧美激情第二页 | 日本在线天堂 | 国语av | 国产黄色在线播放 | 国产精品美女在线 | 中文字幕免费看 | 毛片中文字幕 | 国产91丝袜在线播放 | 亚洲精品一区二区三区蜜桃久 | 国产精品手机在线观看 | 97人人插| 国产一区二区三区视频在线 | 爱爱视频网站 | 国产精品一区二区三区不卡 | 欧美在线日韩 | 国产精品av一区二区 | 国产精品毛片一区二区在线看 | 激情婷婷丁香 | 精品一区二区在线播放 | 国产精品视屏 | 狠狠草视频| 免费观看毛片 | 欧美精品区 | 精品福利在线观看 | 欧美专区在线观看 | 国产激情一区二区三区 | 欧美日韩亚洲视频 | 狠狠五月天 | 国产精品视频一区二区三区 | 四虎影院最新网址 | 97青青草 | 国产农村妇女aaaaa视频 |