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

如何在 EditText 中以不同顏色標記值?

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

問題描述

限時送ChatGPT賬號..

當我寫 "#data" 時,我在 EditText 中寫了一些文本,它的顏色應該改變但不會改變我該怎么做.請檢查以下我使用過的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>

推薦答案

希望這個解決方案會有所幫助..!

Hope this solution will help..!

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

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);
}

這篇關于如何在 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問題)
主站蜘蛛池模板: 成在线人视频免费视频 | 少妇久久久 | 欧美精品tv | 亚洲国产精品久久 | 欧美综合视频 | 久久99精品久久久久久琪琪 | 免费看欧美一级片 | 国产视频在线观看一区二区三区 | 亚洲视频一区在线观看 | 国内自拍偷拍一区 | 久久亚洲国产 | 免费亚洲视频 | www.男人天堂.com | 精品久久99 | 毛片免费观看 | 视频在线日韩 | 男女精品网站 | 日韩国产欧美一区 | 午夜私人影院在线观看 | 一级免费毛片 | 久久久影院 | 天天操天天干天天曰 | 久久亚洲欧美日韩精品专区 | 国产精品爱久久久久久久 | av在线播放国产 | 欧美日韩在线不卡 | 亚洲精品中文字幕av | 国产一区二区三区久久久久久久久 | 久久久精品一区二区三区四季av | 伊人久久精品 | 精品久久久久久久久久久久 | 中文字幕免费中文 | 三级成人在线 | 美女国内精品自产拍在线播放 | 成人免费福利 | 国产精品一区二区三区在线 | 久久国产精品免费一区二区三区 | 欧美一区二区小视频 | av资源网站 | 久久久久久国产一区二区三区 | 97人人澡人人爽91综合色 |