android-支持不同的语言

android-支持不同的语言,第1张

概述我有textView和ListView.我在列表视图中列出了支持语言的列表当我单击任何一种语言时,Textview文本需要更改码Stringlang[]=newString[]{"English","French"};ListViewlistView=(ListView)findViewById(android.R.id.list);ArrayAdapter<String>

我有textVIEw和ListVIEw.我在列表视图中列出了支持语言的列表

当我单击任何一种语言时,TextvIEw文本需要更改

   String lang[] = new String[]{"English","french"};        ListVIEw ListVIEw = (ListVIEw) findVIEwByID(androID.R.ID.List);        ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, androID.R.layout.simple_List_item_1,lang);        ListVIEw.setAdapter(adapter);        TextVIEw text = (TextVIEw)findVIEwByID(R.ID.textBox);    }    @OverrIDe    protected voID onListItemClick(ListVIEw l, VIEw v, int position, long ID) {        TextVIEw tv = (TextVIEw)v;        String selected_lang = tv.getText().toString();        Toast.makeText(this, selected_lang, Toast.LENGTH_LONG).show();    }

注意:
  需要在不使用strings.xml和GoogleAPI的情况下从一种语言翻译成另一种语言

有人知道Google如何将一种语言翻译成另一种语言吗?

解决方法:

在目录值附近创建新的目录值-fr,其中包含文件strings.xml和类似内容

<resources>    <string name="some_string_vith_localization">french translation</string></resources>

并在您的代码中

String lang[] = new String[]{"en","fr"};        ListVIEw ListVIEw = (ListVIEw) findVIEwByID(R.ID.my_List_ID);        ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, androID.R.layout.simple_List_item_1,lang);        ListVIEw.setAdapter(adapter);        TextVIEw text = (TextVIEw)findVIEwByID(R.ID.textBox);    }            @OverrIDe            protected voID onListItemClick(ListVIEw l, VIEw v, int position, long ID) {                TextVIEw tv = (TextVIEw)vIEw.findVIEwByID(R.ID.text_vIEw_to_change);                String selected_lang = tv.getText().toString();                Locale locale2 = new Locale(selected_lang);                Locale.setDefault(locale2);                Configuration config2 = new Configuration();                config2.locale = locale2;                getBaseContext().getResources().updateConfiguration(config2,                        getBaseContext().getResources().getdisplayMetrics());                tv.setText(getResources().getString(R.string.some_string_vith_localization));            }
总结

以上是内存溢出为你收集整理的android-支持不同的语言全部内容,希望文章能够帮你解决android-支持不同的语言所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1210964.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-04
下一篇 2022-06-04

发表评论

登录后才能评论

评论列表(0条)

保存