我试图更改首选项列表背景颜色,该颜色适用于较小的设备,但在平板电脑上留下了难看的白色边距。在寻找解决方案时,我在较大的设备上读到了首选项列表视图放在一个片段中。
关于如何删除它的任何想法?我只需要弄清楚如何设置父母背景颜色?
暂时不允许发布图片,所以屏幕截图为http://i.imgur.com/gjjg5Je.png?1
AppPreferenceActivity.java:
@override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getActionBar().setDisplayHomeAsUpEnabled(true);
// ---load the preferences from an XML file---
addPreferencesFromResource(R.xml.myapppreferences);
int[] colour = getIntent().getExtras().getIntArray("mColour");
getListView().setBackgroundColor(
Color.rgb(colour[0], colour[1], colour[2]));
// Set theme & colour
setTheme(R.style.PreferencesTheme);
getActionBar().setTitle("Preferences");
setIcon();`
的themes.xml:
<?xml version="1.0" encoding="UTF-8"?>
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="PreferencesTheme">
<item name="android:typeface">sans</item>
<item name="android:textColorPrimary">#fff</item>
<item name="android:textColorSecondary">#fff</item>
</style>
myapppreferences.xml
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" >
<PreferenceCategory android:title="Display Settings" >
<ListPreference
android:dialogTitle="Colour..."
android:defaultValue="Red"
android:entries="@array/colourEntries"
android:entryValues="@array/colourValues"
android:key="pref_colour"
android:summary="Choose a default background colour..."
android:title="App Background Colour" >
</ListPreference>
</PreferenceCategory>
<PreferenceCategory android:title="Reminder Settings" >
<ListPreference
android:dialogTitle="Remind me..."
android:defaultValue="The day before"
android:entries="@array/dayRemindEntries"
android:entryValues="@array/dayRemindValues"
android:key="pref_days_before"
android:summary="Remind me..."
android:title="Default reminder..." >
</ListPreference>
</PreferenceCategory>
答案 0 :(得分:2)
addPreferencesFromResource
方法。尝试使用PreferenceFragment
并覆盖onCreateView,如下所示:
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View v = super.onCreateView(inflater, container, savedInstanceState);
if(v != null) {
ListView lv = (ListView) v.findViewById(android.R.id.list);
lv.setPadding(10, 10, 10, 10);
}
return v;
}
此代码取自此回复: Android: How to maximize PreferenceFragment width (or get rid of margin)?