0

你好朋友我想从字符串文件中显示古吉拉特语文本所以我制作了像 values-gu 这样的文件夹并将字符串项目像

 <item name="language">ભાષા પસંદ કરો&lt;/item>

当我在设备上运行时,它显示空白文本,我该如何解决?

我的 MainJava 文件如下:

public class CategoryActivity  extends Activity

 {
Button mButtonCurrency;
Button mButtonGoldSilverPrice;
Intent mIntent;
Locale myLocale;
Spinner mSpinnerLangeage;
public int from;
TextView mTextView;

@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.choose_category);
    mIntent=getIntent();
    mButtonCurrency=(Button)findViewById(R.id.choose_category_btn_currency); 
    mTextView=(TextView)findViewById(R.id.choose_category_txt_language);
    mButtonGoldSilverPrice=(Button)findViewById(R.id.choose_category_btn_gold_silver); 
    mSpinnerLangeage=(Spinner)findViewById(R.id.choose_category_spn_language);
    ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(
            this, R.array.language_name, R.layout.spin_layout);
    adapter.setDropDownViewResource(android.R.layout.select_dialog_singlechoice);
    mSpinnerLangeage.setAdapter(adapter);


    mSpinnerLangeage.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        public void onItemSelected(
                AdapterView<?> adapterView, View view,int pos, long l) {

            from=pos;
            if(pos==1)
            {
                setLocale("en");
            }

            else if (pos==2) {
                setLocale("gu");
            }
        }

        public void onNothingSelected(AdapterView<?> adapterView) {

        }
    });
    mButtonCurrency.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            mIntent=new Intent(getApplicationContext(), CurrencyConverterActivity.class);
            startActivity(mIntent);
        }
    });

    mButtonGoldSilverPrice.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            mIntent=new Intent(getApplicationContext(), GetGoldAndSilverPriceActivity.class);
            mIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            startActivity(mIntent);
        }
    });

}
public void setLocale(String lang) {

    myLocale = new Locale(lang);
    Resources res = getResources();
    DisplayMetrics dm = res.getDisplayMetrics();
    Configuration conf = res.getConfiguration();
    conf.locale = myLocale;
    res.updateConfiguration(conf, dm);
    Intent mIntentRefresh = new Intent(this, CategoryActivity.class);
    mIntentRefresh.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    startActivity(mIntentRefresh);
}

我的字符串文件是包含值,例如

<item name="language">ભાષા પસંદ કરો&lt;/item>

但它在设备中不起作用

4

1 回答 1

0

试试这个代码。

Typeface font = Typeface.createFromAsset(getAssets(), "fonts/RVRaghuGujarati.TTF");   
((TextView)findViewById(R.id.txt)).setTypeface(font);
((TextView)findViewById(R.id.txt)).setText("ભાષા પસંદ કરો");

您需要在项目的assets 文件夹中创建一个名为“fonts”的文件夹。并且,需要下载并添加 Gujarati(.ttf) 字体。

这会奏效。如果这有帮助,请投票给我。

于 2013-09-24T10:44:37.470 回答