私のアプリケーションには、右から左、左から右の 2 つの言語があります。アプリケーション内でロケールを変更します(電話の設定からではありません)。また、resume() 関数でデータをリロードして、UI の変更を確認します。私は値のための2つのフォルダを持っています.1つはvalues-en、もう1つはvalues-faです。textview の方向を RTL と LTR に変更するには、これらのフォルダーに 2 つの styles.xml を配置します。styles.xml (values-en) :
<?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 (values-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>
アプリケーションを実行すると、すべて問題なく、テキストビューの方向はロケールに関連しています。問題は、オプションメニューからアプリの設定から言語を変更すると、データの読み込みは正しいが、方向が正しくないということです。方向の変化を確認するには、別のアクティビティに移動する必要があります。
この問題を解決するには、Html.fromHtml() を使用していて、データに
<p dir="LTR">
と
<p dir="RTL">
タグ?
別の考えられる解決策(コメントのTOMCAに感謝):Androidは実行時にスタイルを動的に変更します
しかし、問題はまだ生きています。