0

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. enter image description here

And this is a screenshot of the Activity in English language, you can see the logo and the menu items: enter image description here

And this is a screenshot of the Activity in Arabic Language, there is no menu or logo appearing: enter image description here

Rami Rasikh
  • 61
  • 1
  • 1
  • 6

2 Answers2

0

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

Ben
  • 1,285
  • 1
  • 9
  • 15
  • this error: Multiple markers at this line ar cannot be resolved to a variable......... R.menu cannot be resolved to a variable – Rami Rasikh Jul 25 '16 at 12:57
  • You may need to clean and rebuild. Can you paste the stack trace of the error. – Ben Jul 25 '16 at 13:57
  • i don't think so. because i can't even run the app with that error. – Rami Rasikh Jul 25 '16 at 14:11
  • What about the error from the build. Also what do your layouts look like between the ar folder and the main folder are they the same? – Ben Jul 25 '16 at 14:30
  • Basically there is no error, the error i told you about happens when i make a folder of (menu-ar) like you told me to do. I added 2 more screenshots above in the main question, you can check them to see the both layouts, the English and the Arabic. – Rami Rasikh Jul 25 '16 at 19:17
  • If you look clearly between the two layouts, you will see the English layout has a black menu bar, contains the logo and the Menu Items. I think the problem maybe in the (drawable) folders where it contains the logo, i think there must be (drawable-ar) or something like that, because the Arabic layout doesn't show the logo. – Rami Rasikh Jul 25 '16 at 19:23
  • Yea my question is more what do the two layout files themselves contain that you're using for that screen not the resource folder. Are the layout files identical. – Ben Jul 25 '16 at 19:45
  • Yes they are, but not 100% , just a matter of spaces and size of some texts. – Rami Rasikh Jul 25 '16 at 19:53
0

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

Community
  • 1
  • 1
waki
  • 1,248
  • 2
  • 17
  • 27
  • i did your steps, but nothing changed with the Menu Item problem. – Rami Rasikh Jul 25 '16 at 12:53
  • @RamiRasikh do you added all your strings ? In my answer I shown just one string example. – waki Jul 25 '16 at 12:54
  • yes i added all my strings to the (strings.xml) file in both languages. and even if i wrote hardcoded strings in the Dialog, that dialog has nothing to do with the Menu Item problem in Arabic language, because it works in the English language. – Rami Rasikh Jul 25 '16 at 13:07