问题描述
- Preference Headers不显示
-
使用Preference-Headers重写PreferenceActivity。但是按照步骤操作之后header没显示,白屏。XMl:
<?xml version="1.0" encoding="utf-8"?> <preference-headers xmlns:android="http://schemas.android.com/apk/res/android"> <preference-headers xmlns:android="http://schemas.android.com/apk/res/android"> <header android:fragment="com.mikebdev.refuel.SettingsActivity$DesignFragment" android:title="@string/pref_header_design" android:summary="@string/pref_header_design_summary" /> <header android:fragment="com.mikebdev.refuel.SettingsActivity$SettingsFragment" android:title="@string/pref_header_units" android:summary="@string/pref_header_units_summary"/> <header android:fragment="com.mikebdev.refuel.SettingsActivity$DatabaseFragment" android:title="@string/pref_header_db" android:summary="@string/pref_header_db_summary"/> </preference-headers> </preference-headers>
SettingsActivity内容:
import android.app.AlertDialog; import android.content.Context; import android.content.DialogInterface; import android.os.Bundle; import android.os.Environment; import android.preference.Preference; import android.preference.PreferenceActivity; import android.preference.PreferenceFragment; import android.preference.PreferenceManager; import android.widget.Toast; import com.google.analytics.tracking.android.EasyTracker; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.util.List; public class SettingsActivity extends PreferenceActivity { public static final String PREFS_NAME = "RFPref"; public static PreferenceManager prefMgr; @Override public void onBuildHeaders(List<Header> target) { loadHeadersFromResource(R.xml.pref_headers, target); } }
不知道哪里出问题?
解决方案
找到原因了,是冗杂的元素引起的,去掉里面的就好了。
解决方案二:
android:fragment="com.mikebdev.refuel.SettingsActivity$DesignFragment"
android:fragment="com.mikebdev.refuel.SettingsActivity$SettingsFragment"
android:fragment="com.mikebdev.refuel.SettingsActivity$DatabaseFragment"
这几个fragment都写了吗?
解决方案三:
请问你是在哪里添加preference-header的???我怎么找半天找不到啊?
时间: 2024-10-09 16:29:35