gpt4 book ai didi

API 17 中的 Android 布局方向问题

转载 作者:搜寻专家 更新时间:2023-11-01 07:50:50 25 4
gpt4 key购买 nike

我要构建一个波斯语应用程序 (RTL)。我的应用包含抽屉式导航。

我在应用程序标签 android:supportsRtl="true"中添加了 Manifest

并在 onCreate() 方法中:getWindow().getDecorView().setLayoutDirection(View.LAYOUT_DIRECTION_RTL);

我知道不到 17 api 的 LayoutDirection 不起作用。

但 api 17 中的图标(工具栏和抽屉导航)是相反的:

API 22 中的结果(正确):

enter image description here

API 17 中的结果(不正确):

enter image description here

我该如何解决这个问题?

这是我的布局:

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context="ir.mhborujerdi.mhb.ebook.MainActivity">

<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">

<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay" />

</android.support.design.widget.AppBarLayout>

<android.support.v4.widget.DrawerLayout
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start"
app:layout_behavior="@string/appbar_scrolling_view_behavior">

<include layout="@layout/content_main" />

<android.support.design.widget.NavigationView
android:id="@+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:headerLayout="@layout/nav_header_main"
app:menu="@menu/activity_main_drawer" />

</android.support.v4.widget.DrawerLayout>

<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="@dimen/fab_margin"
android:src="@android:drawable/ic_dialog_email" />

</android.support.design.widget.CoordinatorLayout>

最佳答案

这个问题之前有人问过,但是如果其他人需要解决这个问题,这将解决它:

ViewCompat.setLayoutDirection( mRoot , ViewCompat.LAYOUT_DIRECTION_LTR );

希望对大家有帮助

关于API 17 中的 Android 布局方向问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35389873/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com