我的應用程序有兩種語言。右側爲左側,左側爲右側。 我更改應用程序內部的區域設置(而不是來自電話設置)。 並在resume()函數上重新加載數據以查看UI上的更改。 我有兩個文件夾values.one values-en,一個值-fa。 將textview的方向更改爲RTL和LTR,將兩個styles.xml放在這些文件夾中。 styles.xml(值烯):styles.xml中的樣式不會在更改區域設置後重新加載
<?xml version="1.0" encoding="utf-8"?>
<resources
xmlns:android="http://schemas.android.com/apk/res/android">
<style name="Direction">
<item name="android:gravity">left</item>
<item name="android:layout_gravity">left</item>
</style>
</resources>
styles.xml(值-FA):
<?xml version="1.0" encoding="utf-8"?>
<resources
xmlns:android="http://schemas.android.com/apk/res/android">
<style name="Direction">
<item name="android:gravity">right</item>
<item name="android:layout_gravity">right</item>
</style>
</resources>
,並使用這種風格,比如我做:
<?xml version="1.0" encoding="UTF-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/menutext"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
style="@style/Direction"
android:padding="0dp"/>
</RelativeLayout>
如果我運行應用程序,一切正常,並且textview的方向與locale相關。 問題在這裏,當我從應用程序的設置從選項菜單中更改語言,數據加載正確,但方向not.and我應該去另一個活動,看到方向的變化。
來解決這個問題,可能會由於我使用Html.fromHtml(我刪除styles.xml)和我的數據有
<p dir="LTR">
和
<p dir="RTL">
標籤?
另一個可能的解決方案(感謝TOMCA徵求意見):android dynamically change style at runtime
,但問題仍然alive.anybody有一個想法?
http://stackoverflow.com/questions/3241729/android-dynamic-change-style-at-runtime – TOMKA
@TOMKA tnx是一個很好的鏈接,但是問題是alive.solution在那個鏈接上沒有用於簡歷活動(我不會離開活動並回到那個調用onCreate) –
我認爲這是因爲樣式aro僅在內容vi時加載新設置。也許只是試圖在改變語言後回憶'setContentView()'?這非常難看,因爲你必須重置所有'findViewById()',但我認爲它會起作用。 – Kyriog