我正在使用希腊语文本和数据制作应用程序但不会显示每个字母。
未显示的字母不是?
标记而是白色空格。文件编码设置为utf8
,在build.gradle
中,我为utf8
设置了编译。
例如:listview中的(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");
然后只需将此类的对象引用到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;
}
}
答案 0 :(得分:0)
也许您的编辑器(Eclipse)不会将文件保存为UTF-8?
无论如何,这些字符串应该存储在Android String Resources中。由于这些文件是XML文件,因此不太可能出现编码问题。
编辑:即使在Android Studio中,您也可以遇到此问题。你可以在这里查看: