如何在AndroidManifest中为指定的活动设置SupportRTL

时间:2018-02-11 09:04:10

标签: android android-layout android-actionbar android-manifest

我从所有活动中移除了操作栏然后我将特定活动添加到操作栏中,当我使用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>

2 个答案:

答案 0 :(得分:1)

启用对RTL布局的支持时:

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

您可以在应用中为每项活动启用此功能。

这表明问题可能在于AppBarLayout / Toolbar的布局。

为了让应用程序正确反映方向,您应该使用适当的属性 - 而不是使用Left / Right,您应该使用Start / End那些。要了解更多信息,请检查Android Developers Blog

您还可以通过选择重构&gt;来使用自动Android Studio选项尽可能添加RTL支持......

enter image description here

答案 1 :(得分:1)

你不能在Manifest.xml中做这件事。

我建议将android:layoutDirection="rtl"设置到您的活动父级布局中,以便仅设置该特定活动支持rtl。

this article has great information about layout directions support.