我需要我的应用程序同时支持 LTR 和 RTL。我正在使用使用支持库的 NavigationView。在这个导航视图的菜单中,我包括了两个项目。其中一个只是一个图标和一个文本,另一个是开关。一切都按预期工作,不包括处于 RTL 模式的 Switch。
以下是 LTR 模式下导航视图的外观:
当设备的语言设置为 RTL 语言时,情况相同:
这些是 Switch 在 RTL 模式下的问题:
1- 未显示图像图标
2-项目的文本未显示
3-开关应该在导航视图的左侧而不是中心
我如何解决它?
这是导航视图菜单的 XML:
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/nav_view_menu">
<group>
<item
android:id="@+id/nav_home"
android:icon="@drawable/ic_home_white_24dp"
android:title="Home" />
<item
android:id="@+id/image_switch_parent"
android:icon="@drawable/ic_photo_library_white_24dp"
android:title="@string/images"
app:actionLayout="@layout/nav_view_switch"
app:showAsAction="always" />
</group>
</menu>
这是开关的实际布局:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.SwitchCompat
android:id="@+id/image_switch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true" />
</RelativeLayout>