简体   繁体   中英

How to show unicode chars in TextView in Android?

This is my activity:

et.addTextChangedListener(mTextEditorWatcher);


private final TextWatcher mTextEditorWatcher = new TextWatcher() {

    public void beforeTextChanged(CharSequence s, int start, int count, int after)
    {


    }

    public void onTextChanged(CharSequence s, int start, int before, int count)
    {
        String name =et.getText().toString();
        String a ="a";
        String b ="b";
        String c ="c";
        String d ="d";
        String e ="e";
        String f ="f";
        String g ="g";
        String h ="h";
        String a1 ="\u24B6";
        String b1 ="\u24B7";
        String c1 ="\u24B7";
        String d1 ="\u24B9";
        String e1 ="\u24BB";
        String f1 ="\u24BB";
        String g1 ="\u24BD";
        String h1 ="\u24BD";
        name =name.replaceAll(a,a1);
        name =name.replaceAll(b,b1);
        name =name.replaceAll(c,c1);
        name =name.replaceAll(d,d1);
        name =name.replaceAll(e,e1);
        name =name.replaceAll(f,f1);
        name =name.replaceAll(g,g1);
        name =name.replaceAll(h,h1);
        tv.setText(name);
    }

    public void afterTextChanged(Editable s)
    {
        et.removeTextChangedListener(this);

        et.addTextChangedListener(this);

    }
};

when write a or b or c in edittext show space in textview what is solution to show unicode? please help

你可以试试:

tv.setText(name).trim(); // the String.trim() method removes leading and trailing white spaces

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM