统一美元的TextView.setText不显示C $ C字符。 [英] Unicode characters not displayed in TextView.setText

查看:344
本文介绍了统一美元的TextView.setText不显示C $ C字符。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不能让一个TextView正确动态显示UNI code字符,它的驾驶我疯狂。我已经剥离下来到最低限度,但居住着的setText TextView的仍然显示钻石,里面还问号的UNI code字符。从人口的strings.xml中的版本显示多字节字符完美。这里的活动:

I can't get a TextView to correctly dynamically display unicode characters, and it's driving me batty. I've stripped it down to the bare minimum, but the TextView populated by setText still shows diamonds with question marks inside them for the unicode characters. The version populated from strings.xml shows the multibyte characters perfectly. Here's the activity:

public class TestMultibyteActivity extends Activity
{
  /** Called when the activity is first created. */
  @Override
  public void onCreate( Bundle savedInstanceState )
  {
    super.onCreate( savedInstanceState );
    setContentView( R.layout.main );
    TextView textField = (TextView) findViewById( R.id.text_field );
    String str = "Tübingen systemportefølje";
    Log.d( "MULTIBYTE", str ); //note that this prints the multibyte chars correctly.
    //EDIT: oh crap, no it doesn't.  might be onto something here...
    textField.setText( str );
  }
}

和这里的布局:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:orientation="vertical"
              android:layout_width="fill_parent"
              android:layout_height="fill_parent">
  <TextView android:id="@+id/text_field"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"/>
  <TextView android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="@string/unicodechars"/>
</LinearLayout>

下面是strings.xml中:

Here's strings.xml:

<?xml version="1.0" encoding="utf-8"?>
<resources>
  <string name="app_name">TestMultibyteActivity</string>
  <string name="unicodechars">Tübingen systemportefølje</string>
</resources>

我在建设有蚂蚁。这是我的default.properties:

I'm building with ant. Here's my default.properties:

target=Google Inc.:Google APIs:8

和这里是我的Andr​​oidManifest.xml

And here's my AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.mycompany.android.multibyte"
      android:versionCode="1"
      android:versionName="1.0">
    <application android:label="@string/app_name" android:icon="@drawable/icon">
        <activity android:name="TestMultibyteActivity"
                  android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
</manifest> 

我已经修补了一切我能想到的,但它似乎是单向code字越来越分裂了的CharSequence接口,我想不通这是为什么。

I've tinkered with everything I can think of, but it seems like unicode characters are getting split by the CharSequence interface, and I can't figure out why.

推荐答案

不幸的是,你不能这样做的,从strings.xml中AFAIK。

Unfortunately, you just can't do it that way from strings.xml AFAIK.

留给你做的两件事情之一。

You're left doing one of two things.

  • 添加Java内部的统一code字符的XML文件中的字符串:

  • Adding the Unicode character within java to the String in the XML file:

字符串str =\ u00A9+    。的getContext()的getString(R.string.your_string);

String str = "\u00A9" + getContext().getString(R.string.your_string);

输入文本为HTML Java中:

Entering the text as HTML in java:

yourTextView.setText(Html.fromHtml(你    字符);

yourTextView.setText(Html.fromHtml("your chars");

希望这是非常有用的。

这篇关于统一美元的TextView.setText不显示C $ C字符。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆