Android utf8上的希腊文字无法正确显示 [英] Greek text on android utf8 not show properly

查看:79
本文介绍了Android utf8上的希腊文字无法正确显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用希腊文字和数据制作应用程序,但并未显示所有字母。
未显示的字母不是标记,而是空白。文件编码设置为 utf8 ,在 build.gradle 中,我已设置 utf8的编译

I'm making app with Greek text and data but not every letter is shown. Letter which is not shown not make ? mark but just white space. File encoding is set to utf8 and in build.gradle, I have set compile for utf8.

例如:在列表视图中显示(agapó)ἀγαπῶ(ἀγαπᾶν)(agapó)γαπ(γαπν)。 XML上的均匀按钮未正确显示同样的问题。

For example: (agapó) ἀγαπῶ (ἀγαπᾶν) in listview is shown as (agapó) γαπ (γαπ ν). Even button on XML not shown properly same problem.

屏幕截图:

  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的数据

And the data from 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

My 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下构建.gradle应该自动设置UT8 ...

Build.gradle under SRC this should automaticaly set UT8...

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

}

编辑:已解决问题BY

PROBLEM SOLVED BY

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

!!!!!!!!!!!!!!!!!! Use typeface Times new roman.ttf and apply to textview by override the adapter method !!! !!!!!!!!!!!!!!!!!!

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

然后只使此类的对象成为引用它的列表适配器

and then just make an object of this class a refer it to an listadapter

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


推荐答案

也许您的编辑器(Eclipse)不会将文件另存为UTF-8吗?

Perhaps your editor (Eclipse) doesn't save the files as UTF-8?

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

Anyway, such strings should be stored in Android String Resources. As these files are XML files it is very unlikely to have encoding problems.

编辑:即使在Android Studio中,您也会遇到此问题。您可以在此处进行检查:

Even in Android Studio you can have this problem. You can check it here:

这篇关于Android utf8上的希腊文字无法正确显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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