我需要为首选项创建活动并在底部(在首选项下)放置一些视图。我创建了布局,但只有第一类标签可见。为什么开关是隐形的?这是我所拥有的:
活动布局.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);
//...
}
首选项.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>
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句