Android - 菜单项不会以阿拉伯语显示 [英] Android - Menu Items don't show up in Arabic
问题描述
我正在制作一个 Android 应用程序,并且想要显示一个包含两个项目的菜单(主页、注销).我的问题正是当我将手机的语言切换为阿拉伯语时,菜单项根本不显示.
I am making an Android app, and want to display a Menu of two items (Home Page , Logout). My problem exactly is the Menu items don't show up at all when i switch my phone's language to Arabic.
当我将手机设置为英语时,菜单项出现并且一切正常.除非当我将手机的语言切换为阿拉伯语时,除菜单外,所有文本都以阿拉伯语显示.根本没有菜单......!请帮忙??
When i set my phone to the English language, the Menu item shows up and all work superfine. unless when i switch the phone's language to Arabic, every text showing up in Arabic except the Menu. No Menu at all..!! please any help??
这里是java代码:
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
public boolean onOptionsItemSelected (MenuItem item){
super.onOptionsItemSelected(item);
switch(item.getItemId()){
case R.id.home_page:
new AlertDialog.Builder(this)
.setTitle("Home Page")
.setMessage("You Are In The Home Page Now")
.setNeutralButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which){
//Do Nothing
}
}).show();
break;
case R.id.logout:
new AlertDialog.Builder(this)
.setTitle("Attention!!")
.setMessage("Do You Really Want To Logout?")
.setNeutralButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which){
//Empty the Sharedpreferences from the ID value
SharedPreferences sp = getSharedPreferences("id_prefs", Activity.MODE_PRIVATE);
sp.edit().putString("id", null).commit();
Intent intent = new Intent(Res_Menu.this, MainActivity.class);
startActivity(intent);
}
}).show();
break;
}
return true;
}
这是菜单文件(main.xml)
And this is the menu file (main.xml)
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="@+id/home_page"
android:orderInCategory="1"
android:showAsAction="ifRoom|withText"
android:title="@string/Reseller_Menu"/>
<item
android:id="@+id/logout"
android:orderInCategory="2"
android:showAsAction="ifRoom|withText"
android:title="@string/logout"/>
</menu>
这是阿拉伯语的strings.xml.路径:(res/values-ar/strings.xml)
And this is the strings.xml for the Arabic language. path:(res/values-ar/strings.xml)
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">مندوب المبيعات</string>
<string name="action_settings">الضبط</string>
<string name="hello_world">!مرحبا العالم</string>
<string name="Welcome_To_Reseller">مرحبا بك في مندوب المبيعات</string>
<string name="phone">الهاتف</string>
<string name="Password">كلمة المرور</string>
<string name="Login">تسجيل دخول</string>
<string name="Name">الإسم</string>
<string name="Register">إنشاء</string>
<string name="Confirm_Password">تأكيد كلمة المرور</string>
<string name="Register_Account">إنشاء حساب جديد</string>
<string name="Reseller_Menu">الصفحة الرئيسية</string>
<string name="Balance_Transfer">تحويل الرصيد</string>
<string name="Buy_Internet_Package">شراء باقة إنترنت</string>
<string name="Account_Details">تفاصيل الحساب</string>
<string name="Enter_Balance_Amount">أدخل المبلغ هنا</string>
<string name="send">إرسال</string>
<string name="Enter_Receiver_Phone">أدخل رقم الهاتف المستقبل هنا</string>
<string name="back">الصفحة السابقة</string>
<string name="Welcome">مرحبا</string>
<string name="my_details">تفاصيل حسابي</string>
<string name="internet_subscription">إشتراك الإنترنت:</string>
<string name="balance">الرصيد:</string>
<string name="view">عرض</string>
<string name="sdg">جنيه سوداني</string>
<string name="logo">logo</string>
<string name="enter_phone">أدخل رقم هاتفك هنا</string>
<string name="enter_password">أدخل كلمة مرورك هنا</string>
<string name="enter_name">أدخل إسمك هنا</string>
<string name="enter_confirm_password">أعد كتابة كلمة مرورك هنا</string>
<string name="amount">المبلغ</string>
<string name="balance_amount">كمية الرصيد</string>
<string name="logout">تسجيل خروج</string>
</resources>
这是我的包资源管理器的屏幕截图,以确保文件和文件夹路径.
And here is a screenshot of my Package Explorer to make sure of the files and folders paths.
这是英文版Activity的截图,你可以看到logo和菜单项:
And this is a screenshot of the Activity in English language, you can see the logo and the menu items:
这是阿拉伯语活动的屏幕截图,没有出现菜单或徽标:
And this is a screenshot of the Activity in Arabic Language, there is no menu or logo appearing:
推荐答案
使用字符串资源.
new AlertDialog.Builder(this)
.setTitle(R.string.home_title)
.setMessage(R.string.you_are_on_home_page)
.setNeutralButton(R.string.btn_ok, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which){
//Do Nothing
}
}).show();
对于两种语言 (en/ar) 添加到 strings.xml
例如,
zh:
For two language (en/ar) add to strings.xml
example,
en:
<string name="you_are_on_home_page">You Are In The Home Page Now</string>
ar:
<string name="you_are_on_home_page">مندوب المبيعات</string>
关于Dialog中的右对齐文本,你可以在这里阅读https://stackoverflow.com/a/6131224
About right justify text in Dialog, you can read here https://stackoverflow.com/a/6131224
这篇关于Android - 菜单项不会以阿拉伯语显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!