Android - Menu Items don't show up in Arabic

♀尐吖头ヾ 提交于 2019-12-25 07:18:40

问题


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??

Here is the java code:

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

}

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>

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.

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:


回答1:


Try adding a menu-ar resource folder and copy your main.xml to it.




回答2:


Use string resources.

    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();

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>

About right justify text in Dialog, you can read here https://stackoverflow.com/a/6131224



来源:https://stackoverflow.com/questions/38566522/android-menu-items-dont-show-up-in-arabic

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!