【问题标题】:How to show unicode chars in TextView in Android?如何在 Android 的 TextView 中显示 unicode 字符?
【发布时间】:2016-12-01 16:22:28
【问题描述】:

这是我的活动:

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

    }
};

当在edittext 中写入 a 或 b 或 c 时,textview 中显示空间是什么解决方案 显示 unicode? 请帮忙

【问题讨论】:

  • 请编辑您的问题,使代码干净无误,如 } 而不是 {,并确保正确缩进,以便向读者呈现“代码”。

标签: java android unicode textview


【解决方案1】:

你可以试试:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-10-24
    • 2016-08-25
    • 1970-01-01
    • 1970-01-01
    • 2011-08-28
    • 2014-09-28
    • 2014-05-26
    • 2018-01-23
    相关资源
    最近更新 更多