gpt4 book ai didi

android - 大屏幕上的首选项 Activity 白边

转载 作者:行者123 更新时间:2023-11-29 00:13:52 25 4
gpt4 key购买 nike

我正在尝试更改偏好列表背景颜色,该颜色适用于较小的设备,但会在平板电脑上留下难看的白边。在寻找解决方案时,我读到在较大的设备上,首选项 ListView 被放置在一个 fragment 中。

关于如何删除它的任何想法?我只需要弄清楚如何设置 parent 的背景颜色吗?

还不允许发布图片,所以这里是屏幕截图: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();`

主题.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>

最佳答案

addPreferencesFromResource 方法在 API 11 及更高版本中已弃用。尝试使用 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)?

关于android - 大屏幕上的首选项 Activity 白边,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27995411/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com