【发布时间】:2011-05-30 04:05:27
【问题描述】:
我无法让 TextView 正确动态地显示 unicode 字符,这让我很生气。我已将其精简到最低限度,但由 setText 填充的 TextView 仍然显示带有 unicode 字符的问号的菱形。从 strings.xml 填充的版本完美地显示了多字节字符。这是活动:
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:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">TestMultibyteActivity</string>
<string name="unicodechars">Tübingen systemportefølje</string>
</resources>
我正在用 ant 构建。这是我的 default.properties:
target=Google Inc.:Google APIs:8
这是我的 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>
我已经修改了我能想到的所有内容,但似乎 Unicode 字符被 CharSequence 接口分割,我不知道为什么。
【问题讨论】:
标签: android