2017-05-26 64 views
1

標題說明了這一切。我發現了幾種使用Facebook的I18nManager將應用程序的默認佈局設置爲RTL的方法,但僅在第二次應用程序啓動時才這樣做。在LTR設備上強制RTL

代碼示例:I18nManager.forceRTL(true)

我不希望給用戶更改語言,因爲應用程序本身是阿拉伯語的能力。我到處都在搜索,但都談論如何支持RTL,而不是實際使用它作爲默認佈局。

有沒有辦法實現這與I18nManager或我必須做一些改變我的本地代碼?

回答

0

這行代碼添加到onCreate方法的最頂部(前超級的setContentView)所有活動的:

getWindow().getDecorView().setLayoutDirection(View.LAYOUT_DIRECTION_RTL); 

,並確保您有supportRtl等於True清單中。

+0

我可以輸入任何東西嗎? – Raymond

+0

沒有..幸運的是沒有任何東西可以導入..但只要確保在清單中有android:supportsRtl =「true」 – Parazok

2

首先在清單中添加rtl支持。

<application 
     android:name=".application.SampleApplication" 
     android:icon="@drawable/ic_launcher" 
     android:label="@string/app_name" 
     android:supportsRtl="true" 
     android:theme="@style/AppTheme"> 
</application> 

然後在您的啓動器活動中,在oncreate上添加以下代碼。

Locale locale = new Locale("ar"); 
    Locale.setDefault(locale); 
    Configuration config = new Configuration(); 
    config.locale = locale; 
getApplicationContext().getResources().updateConfiguration(config, getApplicationContext().getResources().getDisplayMetrics());