我正在使用API 17,希望找到一种方法来将整个应用程序设置为RTL,而不是在每个活动布局中使用<android:layoutDirection="rtl">
。
我正在使用API 17,希望找到一种方法来将整个应用程序设置为RTL,而不是在每个活动布局中使用<android:layoutDirection="rtl">
。
我曾经遇到过同样的问题,你只需要考虑所有已使用的父容器(LinearLayout
,RelativeLayout
,GridView
等)并将布局方向设置为RTL。你可以通过ViewCompat类以编程方式实现此方法,以包括低于17版本的api。
ViewCompat.setLayoutDirection(yourParentContainer, ViewCompat.LAYOUT_DIRECTION_RTL);
请注意,无需单独为子视图设置方向。
最简单、最好的方法
前往 app/res/values/styles
并将以下代码添加到你在 Android Manifest 中定义名称的 <style>
标签中,例如:
<style name"YourMainThemeName" parent="Parent Theme Of Your Choice">
<item name="android:layoutDirection">rtl</item>
</style>
现在请打开 app/manifests/AndroidManifest.xml
文件,并将以下代码行添加到 <application>
标签中:
<application
android:supportsRtl="true"
android:theme="@style/YourMainThemeName">
</application>
现在您的布局方向是从右到左。
<application>
标签内设置android:supportsRtl=true
。 - PattaFeuFeu