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

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

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

問題描述

限時送ChatGPT賬號..

當(dāng)我寫 "#data" 時,我在 EditText 中寫了一些文本,它的顏色應(yī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>

推薦答案

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

Hope this solution will help..!

我使用了這個解決方案,非常有用!就像在你的 editText 上添加 textWatcher 接口并收聽 textChange 并找出單詞是否以 hashTag 開頭然后調(diào)用該單詞的 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);
}

這篇關(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(更改光標在展開的 EditText 中的開始位置)
EditText, adjustPan, ScrollView issue in android(android中的EditText,adjustPan,ScrollView問題)
主站蜘蛛池模板: 97色在线观看免费视频 | 欧美色999 | 欧美日韩在线精品 | 午夜影院网站 | 国产精品一区二区三区四区五区 | 免费毛片网站 | 午夜大片 | 亚洲综合一区二区三区 | 国产乱码精品一区二区三区av | 女生羞羞视频 | 成人区精品一区二区婷婷 | 国产成人综合网 | 亚洲91精品 | 亚洲欧洲精品在线 | 日一日操一操 | 亚洲精品成人在线 | 国产色网| 亚洲欧美一区二区在线观看 | 国产精品欧美一区二区三区不卡 | 午夜在线观看免费 | 欧美高清dvd | 国产欧美一区二区三区在线播放 | 久久精品亚洲欧美日韩精品中文字幕 | 四虎av电影| 丝袜久久 | 久热m3u8 | 国产精品99久久久精品免费观看 | 亚洲一区二区视频 | 成人免费在线视频 | 四色永久 | 日韩在线成人 | 国产91一区二区三区 | 日韩精品一区二区三区中文字幕 | 亚洲毛片一区二区 | 日韩免费视频一区二区 | 欧美最猛黑人xxxⅹ 粉嫩一区二区三区四区公司1 | 日韩欧美精品一区 | 精品日韩一区二区 | 91精品在线看 | caoporn国产| 午夜精品|