0
プリファレンスのアクティビティーを作成し、いくつかのビューを(プリファレンスの下に)下部に配置する必要があります。レイアウトを作成しましたが、最初のカテゴリラベルだけが表示されます。スイッチが見えないのはなぜですか?ここで私が持っているものです。アクティビティーの一部としてのプリファレンスフラグメント
activity_layout.xml:
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <ScrollView android:id="@+id/settingsForm" android:layout_width="match_parent" android:layout_height="match_parent"> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <fragment android:id="@+id/settingsFragment" android:layout_width="match_parent" android:layout_height="wrap_content" class="com.example.SettingsFragment"/> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical"> <!-- views --> </LinearLayout> </LinearLayout> </ScrollView> </LinearLayout>
SettingsFragment exends PreferenceFragment:
public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.preferences); //... }
あるpreferences.xml
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"> <PreferenceCategory android:title="@string/pref_work_storage_title" android:key="pref_work_category"> <SwitchPreference android:key="pref_work_unavailable" android:defaultValue="true" android:summaryOn="@string/pref_work_available" android:summaryOff="@string/pref_work_unavailable"/> </PreferenceCategory> </PreferenceScreen>