【问题标题】:Greek text on android utf8 not show properlyandroid utf8 上的希腊文本无法正确显示
【发布时间】:2013-11-08 08:58:20
【问题描述】:

我正在使用希腊文本和数据制作应用程序,但并未显示每个字母。 未显示的字母不会使? 标记,而只是空格。文件编码设置为utf8,在build.gradle,我设置了编译utf8

例如:(agapó) ἀγαπῶ (ἀγαπᾶν) 在列表视图中显示为(agapó) γαπ (γαπ ν)。甚至 XML 上的按钮也没有正确显示同样的问题。

截图:

  private void inicialization() {

    sound = (ImageView) findViewById(R.id.sound);
    home = (ImageView) findViewById(R.id.home);
    home.setOnClickListener(this);

    setData();

    listwords = (ListView) findViewById(R.id.listwords);
    adapter = new ArrayAdapter<String>(this, R.layout.adapteritem, R.id.greek_word, Timeslist);
    listwords.setAdapter(adapter);
    listwords.setOnItemClickListener(this);

    play = (Button) findViewById(R.id.play);
    stop = (Button) findViewById(R.id.stop);
    play.setOnClickListener(this);
    stop.setOnClickListener(this);

    tv1 = (TextView)findViewById(R.id.text1);
    tv2 = (TextView)findViewById(R.id.text2);
    tv3 = (TextView)findViewById(R.id.text3);
    tv4 = (TextView)findViewById(R.id.text4);
    tv5 = (TextView)findViewById(R.id.text5);

    setPlayer();
}

private void setData() {

    int index;
    index = getIntent().getIntExtra("index", 0);

    switch (index){
        case 0:
            if(lang){
                Timeslist = GlobalTimes.Times1ListCZ; // from global class of arrays
                TimesAudio = GlobalTimes.Times1AudioCZ;
                TimesWords = GlobalTimes.Times1WordsCZ;
            }
            if(!lang){
                Timeslist =  GlobalTimes.Times1List;
                TimesAudio = GlobalTimes.Times1Audio;
                TimesWords = GlobalTimes.Times1Words;
            }
            break;
    }
}

还有来自 Globalclass 的数据

public class GlobalTimes {

public static String[] Times1List = { "(agapó) ἀγαπῶ (ἀγαπᾶν)", "(agó) ἄγω", "(airó) αἴρω", "(akúó) ἀκούω", "(hamartanó) ἁμαρτάνω", "(anabainó) ἀναβαίνω"};
public static Integer[] Times1Audio = { R.raw.miluji, R.raw.vedu, R.raw.zdviham, R.raw.slysim, R.raw.hresim, R.raw.jdunahoru };
public static String[][] Times1Words = {

        {
                "ἀγαπῶ",     
                "ἀγαπᾶν",    
                "ἀγαπήσω",   
                "ἠγάπησα",  
                "ἠγάπηκα",   
                "ἠγάπημαι",  
                "ἠγαπήθην", 
                "miluji"
        },
        {
                "ἄγω",
                "x",
                "ἄξω",
         ...
         ...

我的adapteritem.xml

<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="wrap_content"
android:layout_width="wrap_content">

<TextView
    android:id="@+id/greek_word"
    android:layout_height="50dp"
    android:gravity="center_vertical"
    android:text="text"
    android:textSize="12dp"
    android:padding="3dp"
    android:visibility="visible"
    android:layout_width="fill_parent"
    android:textColor="#FF000000"
    android:background="#FFFFFFFF" />

SRC 下的 Build.gradle 这应该会自动设置 UT8...

tasks.withType(Compile) {
options.encoding = 'utf-8'

}

编辑:解决的问题

!!!!!!!!!!!!!!!!!! 使用字体 Times new roman.ttf 并通过覆盖适配器方法应用于 textview !!! !!!!!!!!!!!!!!!!!!!!!

font = Typeface.createFromAsset(getAssets(), "times.ttf");

然后将这个类的一个对象引用到一个列表适配器

 public class MyAdapter extends ArrayAdapter<String> {
    public Context context;
    public String[] values;
    private Typeface font;

    public MyAdapter(Context context, String[] values, Typeface font) {
        super(context, R.layout.adapteritem, values);
        this.context = context;
        this.values = values;
        this.font = font;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

        View rowView = inflater.inflate(R.layout.adapteritem, parent, false);
        TextView textView = (TextView) rowView.findViewById(R.id.greek_word);

        textView.setTypeface(font);
        textView.setText(values[position]); // maybe not the best line of code but i dont know how do it better.. but works :)

        return rowView;
    }
}

【问题讨论】:

  • 这些字母是动态数据还是静态数据?
  • 静态数据例如 { "ἀγαπῶ", "ἀγαπᾶν", "ἀγαπήσω", "ἠγάπησα", "ἠγάπηκα", "ἠγάπημαι", "ἠγαπήθην", "miluji" }
  • 你在使用 textview 吗?你也可以粘贴你的代码吗
  • 没有我将数据放入 Listview
  • 你不要使用自定义列表视图并在文本视图中设置这些

标签: android encoding android-studio


【解决方案1】:

也许您的编辑器 (Eclipse) 没有将文件保存为 UTF-8?

无论如何,这样的字符串应该存储在Android String Resources 中。由于这些文件是 XML 文件,因此不太可能出现编码问题。

编辑:即使在 Android Studio 中,您也可能遇到此问题。你可以在这里查看:

【讨论】:

  • iam 使用 Android Studio,当我右键单击 android studio 时,无论我想要什么,我都选择了文件编码,我将其设置为 UTF8,在 Build.gradle 中我将编码设置为 utf8 查看编辑。跨度>
  • 我已经设置了UTF8,就像你的截图一样
  • 尝试在布局文件中直接设置文本的地方放置一个(新的)TextView。使用其中一个字符丢失的单词。 TextView 是否正确呈现单词?
  • 好的。然后我认为这可能是某种字体问题。这些(不可见的)角色有那么特别吗?它们是从标准的希腊字母表中提取的吗?你如何构建像'?你的键盘上有两个按键吗?
  • 我的键盘上没有它们。是的,它们很特别,因为它们不是标准的希腊语 aplhabet 因为有些字符有“comas”和“'”等等。你的意思是什么像“'?”这样的上升?我有捷克语键盘.. 但我不认为字体问题可能是但我可以将字体更改为(新罗马时代)以在设备上显示吗?如何?会有所不同吗?
猜你喜欢
  • 2016-10-05
  • 2016-07-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多