2014-02-22 167 views
3

這是PreferenceScreen的xml文件 PreferenceCategory隨我需要出現RTL,但是其他組件出現LTR 如何製作thim RTL?Android:preferencescreen從右到左

我綁定遵循此link,我添加了android:supportsRtl =「true」到我的清單文件中的元素,但沒有發生任何事情!

<?xml version="1.0" encoding="utf-8"?> 
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:gravity="end"> 

    <PreferenceScreen 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:gravity="end" 
      android:title="@string/about_feedex"> 
      <intent 
       android:action="android.intent.action.VIEW" 
       android:targetPackage="com.arrafni.news" 
       android:targetClass="com.arrafni.news.activity.AboutActivity"/> 
    </PreferenceScreen> 

    <PreferenceCategory 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:gravity="end" 
     android:title="@string/settings_category_refresh"> 

     <CheckBoxPreference 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:gravity="end" 
      android:defaultValue="true" 
      android:key="refresh.enabled" 
      android:summary="@string/settings_refresh_enabled_description" 
      android:title="@string/settings_refresh_enabled" /> 

     <ListPreference 
      android:name="@string/settings_refresh_interval" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:gravity="end" 
      android:defaultValue="1800000" 
      android:dependency="refresh.enabled" 
      android:entries="@array/settings_intervals" 
      android:entryValues="@array/settings_interval_values" 
      android:inputType="number" 
      android:key="refresh.interval" 
      android:summary="@string/settings_refresh_interval_description" 
      android:title="@string/settings_refresh_interval" /> 

     <CheckBoxPreference 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:gravity="end" 
      android:defaultValue="false" 
      android:key="refreshonopen.enabled" 
      android:summary="@string/settings_refresh_on_open_description" 
      android:title="@string/settings_refresh_on_open" /> 

     <CheckBoxPreference 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:defaultValue="false" 
      android:gravity="end" 
      android:key="refreshwifionly.enabled" 
      android:summary="@string/settings_refresh_wifi_only_description" 
      android:title="@string/settings_refresh_wifi_only" /> 
    </PreferenceCategory> 

    <PreferenceCategory 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:title="@string/settings_category_content_presentation"> 

     <CheckBoxPreference 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:defaultValue="true" 
      android:gravity="end" 
      android:disableDependentsState="true" 
      android:key="lighttheme" 
      android:summary="@string/settings_lighttheme_description" 
      android:title="@string/settings_lighttheme" /> 

     <ListPreference 
      android:name="@string/settings_keep_time" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:defaultValue="4" 
      android:gravity="end" 
      android:entries="@array/settings_keep_times" 
      android:entryValues="@array/settings_keep_time_values" 
      android:inputType="number" 
      android:key="keeptime" 
      android:summary="@string/settings_keep_time_description" 
      android:title="@string/settings_keep_time" /> 

     <ListPreference 
      android:name="@string/settings_font_size" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:defaultValue="0" 
      android:gravity="end" 
      android:entries="@array/settings_font_sizes" 
      android:entryValues="@array/settings_font_size_values" 
      android:inputType="number" 
      android:key="fontsize" 
      android:summary="@string/settings_font_size_description" 
      android:title="@string/settings_font_size" /> 

     <CheckBoxPreference 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:defaultValue="false" 
      android:gravity="end" 
      android:disableDependentsState="true" 
      android:key="pictures.disable" 
      android:summary="@string/settings_disable_pictures_description" 
      android:title="@string/settings_disable_pictures" /> 

     <CheckBoxPreference 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:defaultValue="false" 
      android:gravity="end" 
      android:dependency="pictures.disable" 
      android:key="pictures.fetch" 
      android:summary="@string/settings_fetch_pictures_description" 
      android:title="@string/settings_fetch_pictures" /> 

     <CheckBoxPreference 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:defaultValue="false" 
      android:gravity="end" 
      android:key="display_oldest_first" 
      android:summary="@string/settings_display_oldest_first_description" 
      android:title="@string/settings_display_oldest_first" /> 
    </PreferenceCategory> 

    <PreferenceCategory 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:gravity="end" 
     android:title="@string/settings_category_notifications"> 

     <CheckBoxPreference 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:defaultValue="true" 
      android:gravity="end" 
      android:key="notifications.enabled" 
      android:summary="@string/settings_notifications_enabled_description" 
      android:title="@string/settings_notifications_enabled" /> 

     <RingtonePreference 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:gravity="end" 
      android:dependency="notifications.enabled" 
      android:key="notifications.ringtone" 
      android:ringtoneType="notification" 
      android:summary="@string/settings_notifications_ringtone_description" 
      android:title="@string/settings_notifications_ringtone" /> 

     <CheckBoxPreference 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:dependency="notifications.enabled" 
      android:gravity="end" 
      android:key="notifications.vibrate" 
      android:summary="@string/settings_notifications_vibrate_description" 
      android:title="@string/settings_notifications_vibrate" /> 
    </PreferenceCategory> 

    <PreferenceCategory 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:gravity="end" 
     android:textDirection = "rtl" 
     android:title="@string/settings_category_network"> 

     <PreferenceScreen 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:gravity="end" 
      android:textDirection = "rtl" 
      android:title="@string/settings_screen_proxy"> 

      <CheckBoxPreference 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:gravity="end" 
       android:textDirection = "rtl" 
       android:key="proxy.enabled" 
       android:title="@string/settings_proxy_enabled" /> 

      <CheckBoxPreference 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:gravity="end" 
       android:textDirection = "rtl" 
       android:dependency="proxy.enabled" 
       android:key="proxy.wifionly" 
       android:summary="@string/settings_proxy_wifi_only_description" 
       android:title="@string/settings_proxy_wifi_only" /> 

      <EditTextPreference 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:gravity="end" 
       android:textDirection = "rtl" 
       android:dependency="proxy.enabled" 
       android:key="proxy.host" 
       android:title="@string/settings_proxy_host" /> 

      <EditTextPreference 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:dependency="proxy.enabled" 
       android:gravity="end" 
       android:textDirection = "rtl" 
       android:inputType="number" 
       android:key="proxy.port" 
       android:title="@string/settings_proxy_port" /> 

      <ListPreference 
       android:name="@string/settings_proxy_type" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:textDirection = "rtl" 
       android:gravity="end" 
       android:defaultValue="0" 
       android:dependency="proxy.enabled" 
       android:entries="@array/settings_proxy_types_names" 
       android:entryValues="@array/settings_proxy_types" 
       android:inputType="number" 
       android:key="proxy.type" 
       android:title="@string/settings_proxy_type" /> 
     </PreferenceScreen> 
    </PreferenceCategory> 

</PreferenceScreen> 

回答

2

你解決了這個問題嗎?

這有2級可能的解決方法:延長每一個喜好,並添加:

@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1) 
    @Override 
    protected View onCreateView(final ViewGroup paramViewGroup) 
    { 
    final View view=super.onCreateView(paramViewGroup); 
    if(VERSION.SDK_INT>=VERSION_CODES.JELLY_BEAN_MR1) 
     view.setLayoutDirection(View.LAYOUT_DIRECTION_LOCALE); 
    return view; 
    } 

另一個更簡單一個是關於活動:

if(VERSION.SDK_INT>=VERSION_CODES.JELLY_BEAN_MR1) 
    getListView().setLayoutDirection(View.LAYOUT_DIRECTION_LOCALE); 

然而,對於這兩種解決方法,我可以沒有找到如何通過按下一些首選項來處理顯示的對話框。

0

自定義CheckBoxPreference和EditTextPreference,......到正確的方向:

public class EditTextPreferenceRTL extends EditTextPreference { 

public EditTextPreferenceRTL(Context context, AttributeSet attrs) { 
    super(context, attrs); 
} 

@Override 
protected View onCreateView(ViewGroup parent) { 
    View view = super.onCreateView(parent); 

    RelativeLayout layout = (RelativeLayout) ((LinearLayout) view).getChildAt(1); 
    layout.setGravity(Gravity.RIGHT); 
    return view; 
} 
} 


public class CheckBoxPreferenceRTL extends CheckBoxPreference { 

public CheckBoxPreferenceRTL(Context context, AttributeSet attrs) { 
    super(context, attrs); 
} 

@Override 
protected View onCreateView(ViewGroup parent) { 
    View view = (LinearLayout)super.onCreateView(parent); 
    RelativeLayout layout = (RelativeLayout) ((LinearLayout) view).getChildAt(1); 
    ((LinearLayout)view).removeViewAt(1); 
    layout.setGravity(Gravity.RIGHT); 
    ((LinearLayout)view).addView(layout); 
    return view; 
} 


} 
相關問題