1

現在、preference.xml で有効になっているチェックボックス設定が無効になっているという問題があります。これは、Metarial デザインへの移行後に発生しました。プログラムでビューを有効にしようとしましたが、役に立ちませんでした。

(スクリーンショットを見せたいのですが、私の担当者はまだ十分に高くありません:/)

私の好み.xml

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

    <PreferenceCategory android:title="Network Service" >

        <CheckBoxPreference
            android:enabled="true"
            android:key="@string/communication_option"
            android:selectable="true"
            android:defaultValue="true"
            android:shouldDisableView="false"
            android:summary="Allows down- and upload."
            android:title="Enable server communication" />

        <CheckBoxPreference
            android:disableDependentsState="false"
            android:enabled="true"
            android:dependency="@string/communication_option"
            android:key="@string/wifi_sync_option"
            android:selectable="true"
            android:defaultValue="true"
            android:shouldDisableView="true"
            android:summary="Do not use mobile bandwidth to download"
            android:title="WiFi synchronization only" />

    </PreferenceCategory>
</PreferenceScreen>

私の好みフラグメント

public class FragmentPreference extends PreferenceFragment implements
    SharedPreferences.OnSharedPreferenceChangeListener {


@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // Load the preferences from an XML resource
    addPreferencesFromResource(R.xml.preferences);

    // added to make sure it really is enabled
    CheckBoxPreference cbp = (CheckBoxPreference) getPreferenceManager()
            .findPreference(getString(R.string.communication_option));
    cbp.setEnabled(true);
    cbp.setShouldDisableView(false);

}

新しいツールバーを追加できるように、Theme.AppCompat.Light.NoActionBar テーマを使用しています。

私が気付いたもう1つのことは、画面の向きが横向きに変わると設定が有効として表示され、設定が無効として表示されていても、設定をクリック/チェック/チェック解除できることです。

4

2 に答える 2

3

いくつかの試行錯誤の後、私は設定を過負荷にしていることがわかりました。動作するスリムでクリーンなバージョンは次のようになります。

<PreferenceCategory android:title="Network Service" >

    <CheckBoxPreference
        android:key="@string/communication_option"
        android:defaultValue="true"
        android:summary="Allows down- and upload."
        android:title="Enable server communication" />

    <CheckBoxPreference
        android:dependency="communication_option"
        android:key="@string/wifi_sync_option"
        android:defaultValue="true"
        android:summary="Do not use mobile bandwidth to download"
        android:title="WiFi synchronization only" />

</PreferenceCategory>

public class FragmentPreference extends PreferenceFragment implements
            SharedPreferences.OnSharedPreferenceChangeListener {     

        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);

            // Load the preferences from an XML resource
            addPreferencesFromResource(R.xml.preferences);
        }
}
于 2015-02-19T11:14:40.210 に答える