我需要为首选项创建活动,并在底部放置一些视图(在首选项下)。我创建了布局,但只有第一个类别标签可见。为什么切换是隐形的?这就是我所拥有的:
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释放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>