3
votes

L'icône MenuItem ne s'affiche pas correctement dans les mises en page RTL

Dans RTL, l'icône de l'élément du menu d'options ne s'affiche pas correctement !! mais en LTR, tout est bien et magnifiquement affiché.

Avec l'aide de cette commande, je crée le programme RTL

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:gravity="start"
    android:layoutDirection="rtl"
    android:layout_gravity="start">
    <item
        android:id="@+id/action_more"
        android:icon="@drawable/ic_add_white_24dp"
        android:title=""
        app:showAsAction="always">
        <menu>
            <item
                android:id="@+id/action_settings"
                android:icon="@drawable/ic_wb_sunny_black_24dp"
                android:title="آیتم شماره 1"/>

            <item
                android:id="@+id/action_settings2"
                android:icon="@drawable/ic_star_black_24dp"
                android:title="آیتم شماره 2"/>

            <item
                android:id="@+id/action_settings3"
                android:icon="@drawable/ic_wb_sunny_black_24dp"
                android:title="آیتم شماره 3"/>
        </menu>
    </item>
</menu>

Mon menu layout.xml

getWindow().getDecorView().setLayoutDirection(View.LAYOUT_DIRECTION_RTL);

Aidez-moi à résoudre ce problème.

Capture d'écran


2 commentaires

Veuillez publier une capture d'écran pour montrer ce qui ne s'affiche pas correctement.


lien sceenshot ajouté au message.


4 Réponses :


-1
votes

Vous devez créer un autre dossier pour votre langue

ex: layout-ar pour la langue arabe


0 commentaires

4
votes

Fenêtre contextuelle de la barre d'outils personnalisée Thème, remplacement

android:layout_marginStart android:layout_marginEnd

Ajoutez d'abord ces lignes à votre res / values / styles.xml

......
<android.support.v7.widget.Toolbar
    android:id="@+id/toolbar"
    android:layout_width="match_parent"
    android:layout_height="?attr/actionBarSize"
    android:background="@color/colorPrimary"
    app:navigationIcon="@drawable/arrow_back"
    android:theme="@style/ThemeOverlay.AppCompat.ActionBar"
    app:popupTheme="@style/PopupTheme"
    app:title="@string/toolbar_title"/>
......

puis définissez le popupTheme de la barre d'outils sur 'PopupTheme' comme indiqué ci-dessus, comme ceci:

<style name="PopupTheme" parent="ThemeOverlay.AppCompat.Light">
    <item name="android:layout_marginStart">2dp</item>
    <item name="android:layout_marginEnd">2dp</item>
</style>

À votre santé!


0 commentaires

4
votes

J'ai rencontré le même problème dans la mise en page RTL.Si vous utilisez la bibliothèque de support ou AndroidX, vous pouvez appliquer cette solution simple:

  1. Dans votre projet, créez un nouveau fichier de mise en page dans res -> layout avec ce nom abc_list_menu_item_icon.xml .
  2. Copiez le code ci-dessous dans le fichier de l'étape 1.

    <?xml version="1.0" encoding="utf-8"?>
    <!-- Copyright (C) 2007 The Android Open Source Project
    
         Licensed under the Apache License, Version 2.0 (the "License");
         you may not use this file except in compliance with the License.
         You may obtain a copy of the License at
    
              http://www.apache.org/licenses/LICENSE-2.0
    
         Unless required by applicable law or agreed to in writing, software
         distributed under the License is distributed on an "AS IS" BASIS,
         WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
         See the License for the specific language governing permissions and
         limitations under the License.
    -->
    
    <ImageView xmlns:android="http://schemas.android.com/apk/res/android"
               android:id="@+id/icon"
               android:layout_width="wrap_content"
               android:layout_height="wrap_content"
               android:layout_gravity="center_vertical"
               android:layout_marginLeft="8dip"
               android:layout_marginRight="-8dip"
               android:layout_marginStart="8dip"
               android:layout_marginEnd="-8dip"
               android:layout_marginTop="8dip"
               android:layout_marginBottom="8dip"
               android:scaleType="centerInside"
               android:duplicateParentState="true"/>
    


0 commentaires

0
votes

Le correctif est disponible dans appcompat: 1.3.0-alpha02

Dans changelog:

Prise en charge de RTL dans les éléments de menu avec des icônes (I2f5c5): https://android-review.googlesource.com/c/platform/frameworks/support/+/1353122


0 commentaires