如何在AndroidManifest中为指定的Activity设置RTL支持

6
我已经从所有活动中删除了操作栏,然后我将一个操作栏放到特定的活动中,并在该活动中使用SupportsRtl(更改标题位置),但标题位置仍未更改。
样式:
<resources>

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
</style>

<style name="myTheme" parent="Theme.AppCompat.Light">
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
    <item name="android:textColorPrimary">#FFFFFF</item>
</style>

</resources>

清单:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.user.classmanager">

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">
    <activity android:name=".MainActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

    <activity android:name=".FirstTab" />
    <activity android:name=".SecondTab" />
    <activity android:name=".ThirdTab" />

    <activity android:name=".AddNewClass"
        android:theme = "@style/myTheme"
        android:supportsRtl="true"  <==== DONT WORK
        android:label="اضافه کردن کلاس">
    </activity>
</application> </manifest>

在你的 .AddNewClass 中,你获取到了标题吗? - Ali
你的目标 SDK 是什么?在 application 标签中使用 android:supportsRtl="true" 只能在 API 17 及以上版本中使用。 - Yupi
2个回答

5

1
通过设置 android:layoutDirection="rtl",您不仅支持从右到左的布局方向,而且强制所有语言都使用该方向(从左到右将不再起作用)。 - paulina_glab
是的,但只有当整个页面使用一种RTL语言时才有效。 - alizeyn
2
谢谢回答我的问题,我在xml目标中测试>>android:layoutDirection="rtl"<<,但仍然不起作用,但我找到了问题。这段代码对我有用:getWindow().getDecorView().setLayoutDirection(View.LAYOUT_DIRECTION_RTL) @paulina_glab - Nima Khalili

2

当您启用像这样的RTL布局支持:

<application
    ...
    android:supportsRtl="true">

你可以启用此功能以用于应用中的每个活动
这表明问题可能在你的AppBarLayout/ Toolbar布局中。为了使应用程序正确反映方向,你应该使用适当的属性,而不是使用Left/Right,而应该使用Start/End。更多信息,请查看Android Developers Blog
你还可以通过选择重构>尽可能添加RTL支持...来使用Android Studio中的自动选项。 enter image description here

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接