我在设计偏好屏幕时遇到了非常奇怪的问题.虽然我没有给出任何布局余量,但是左边留有一些空间.
如下图所示:

XML:
<PreferenceScreen android:title="demo" >
<CheckBoxPreference
android:defaultValue="false"
android:key="prefSync"`
android:title="Auto Sync" />
</PreferenceScreen>
Run Code Online (Sandbox Code Playgroud)
我在屏幕上添加复选框首选项时做错了什么?
我有以下XML代码CheckBoxPreference:
<CheckBoxPreference
android:key="pref_boot_startup"
android:title="Auto start"
android:defaultValue="true" />
Run Code Online (Sandbox Code Playgroud)
但是,当我在代码中检索首选项时,值为false.
sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
boolean autoStart = sharedPreferences.getBoolean("pref_boot_startup", true);
Run Code Online (Sandbox Code Playgroud)
我的autoStart变量返回false.
这有什么特别的原因吗?我错过了将默认值设置为的步骤true吗?
我目前正在使用来自Web服务的内容动态地构建带有复选框的行列表.但是,这ListView需要做的事情几乎PreferenceActivity可以完成.
由于内容是动态的,我不知道行数,所以我不能CheckBoxPreference用XML 创建每一行.我如何建立PreferenceActivity一个CheckBoxPreference动态显示未知数字行?
我有PreferenceScreen和一些PreferenceCheckBoxes.我想更改textColor和textSize的标题和摘要以及CheckBox的图像选中和取消选中.所以我android:layout用来改变这个属性.
我的ChceckBoxPreference:
<CheckBoxPreference
android:layout="@layout/preference_checkbox"
android:key="temp"
android:title="@string/title"
android:summary="@string/summary"
android:defaultValue="true"
/>
Run Code Online (Sandbox Code Playgroud)
当我使用android:widgetLayout它看起来很奇怪.这是我的preference_checkbox.xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="10dp"
>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_alignParentLeft="true"
android:layout_marginLeft="10dp"
>
<TextView
android:id="@+android:id/title"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="@color/gray"
android:textSize="20sp"
/>
<TextView
android:id="@+android:id/summary"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="@color/gray"
android:textSize="14sp"
/>
</LinearLayout>
<CheckBox
android:id="@+android:id/checkbox"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_alignParentRight="true"
android:layout_marginRight="10dp"
/>
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
带有id @+android:id/title和摘要的标题@+android:id/summary显示正确的值.但是,尽管默认值和id的复选框@+android:id/checkbox无法正常工作.它没有显示正确的值,我无法更改首选项中保留的值.不使用任何布局,我可以通过触摸整个CheckBoxPreference来更改复选框的值.但现在(使用我的布局)我只能通过触摸此复选框来更改复选框的值.如何以正确的方式为所有功能制作CheckBoxPreference的布局?
我只有一个PreferenceScreen包含CheckBoxPreferences(要选择的类别).我需要一个选项来检查/取消选中所有这些选项.我有以下代码来完成这项工作,但是有一个问题:屏幕上的复选框没有更新 - 我需要在视图上调用一些无效的东西.
这是我现在的代码:
private void checkAll() {
SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(this);
SharedPreferences.Editor editor = settings.edit();
@SuppressWarnings("unchecked")
Map<String, Boolean> categories = (Map<String, Boolean>) settings.getAll();
for(String s : categories.keySet()) {
editor.putBoolean(s, true);
}
editor.commit();
}
private void uncheckAll() {
SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(this);
SharedPreferences.Editor editor = settings.edit();
@SuppressWarnings("unchecked")
Map<String, Boolean> categories = (Map<String, Boolean>) settings.getAll();
for(String s : categories.keySet()) {
editor.putBoolean(s, false);
}
editor.commit();
this.restart();
}
Run Code Online (Sandbox Code Playgroud)
这段代码工作正常但我需要以某种方式刷新视图以查看结果imediatelly(不仅仅是在关闭并重新启动设置活动之后).
谢谢大家的任何建议!
您好我需要知道如何以编程方式设置值.
我正在使用该代码
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
.
.
.
SharedPreferences.Editor geted = prefs.edit();
geted.putBoolean("checkBox_Schedule", false);
geted.commit();
Run Code Online (Sandbox Code Playgroud)
但我没有看到任何变化
我的checkboxPreference的xml代码是
<CheckBoxPreference
android:defaultValue="false"
android:dependency="checkBox"
android:key="checkBox_Schedule"
android:summary="On/Off"
android:title="Schedule" />
Run Code Online (Sandbox Code Playgroud)
一种解决方案是做
startActivity(new Intent(SetPreference.this, SetPreference.class));
Run Code Online (Sandbox Code Playgroud)
但这不是我想要做的.
例如:我的首选项屏幕中有三个复选框,listpreference(A,B,C)每个复选框有3个不同的复选框.我想让用户一次只选择一个复选框.我如何实现这一目标?
首选项屏幕中没有单选按钮
我不能使用Listpreference,如果我可以使用它
ListPreference
android:key="livewallpaper_testpattern"
android:title="@string/livewallpaper_settings_title"
android:summary="@string/livewallpaper_settings_summary"
android:entries="@array/livewallpaper_testpattern_names"
android:entryValues="@array/livewallpaper_testpattern_prefix"
Run Code Online (Sandbox Code Playgroud)这个Listprefrence的数组是"蓝色","红色","白色"
如果是蓝色ListPreference A取决于蓝色
如果它是红色ListPreference B依赖于红色
如果是白色ListPreference C取决于白色
我怎样才能做到这一点?
我在谷歌搜索3-4页,这里几乎所有关于这些,但我找不到任何答案.
最好的祝福,
提前致谢..
我有一个首选项xml文件,在某些时候它看起来像这样:
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
android:title="Hello there">
<!-- Profile ** -->
<PreferenceScreen
android:key="profile"
android:summary="Let app access my profile info such as name, picture and other account information."
android:title="User Profile">
<CheckBoxPreference
android:defaultValue="true"
android:key="pref_profile"
android:summary="Let app access my profile such as name, picture and other account information."
android:title="My Profile" />
Run Code Online (Sandbox Code Playgroud)
如您所见,我有2个preferenceScreen。我想获取CheckBoxPreference的preferenceScreen(所以带有key的profile屏幕:profile)。当我使用时:
PreferenceScreen prefScreen = getPreferenceScreen();
Run Code Online (Sandbox Code Playgroud)
我得到一个标题为:你好。我如何获得此checkBoxPreference的直接父(第一父)屏幕?我想要得到它,以便我可以禁用或启用其视图。
有什么想法吗?谢谢!!
android preference checkboxpreference preferencescreen android-settings
我想在WPF中创建不可能的复选框(来自C#代码).只允许取消选中.
我该怎么做?
PS.
在Click事件上编写事件处理程序,在检查后立即取消选中复选框是不可接受的.
[edit]
应始终启用复选框,以便用户可以认为可以选中复选框.这很奇怪,但它是特定的程序.
嗨,我正在处理消息设置作为首选项.
我想改变android:title和android:CheckboxPreference的摘要文本字体大小.

为此,我正在尝试下面的代码
<PreferenceCategory
android:key="prefcategory1"
android:title="GENERAL SETTINGS..." >
<CheckBoxPreference
android:defaultValue="false"
android:enabled="true"
android:key="checkBoxdelete"
android:layout="@layout/mylayout" <!--linking it to mylayout.xml -->
android:summary="Deletes old messages as limits are reached"
android:title="Delete old messages" />
</PreferenceCategory>
Run Code Online (Sandbox Code Playgroud)
和mylayout.xml
<TextView android:id="@+android:id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="8dp"
android:textColor="#FFFFFF"
android:textSize="30px"
android:textStyle="bold"/>
<TextView android:id="@+android:id/summary"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="8dp"
android:textColor="#FFFFFF"
android:textSize="20px"
android:textStyle="bold"/>
Run Code Online (Sandbox Code Playgroud)
通过使用它,文本大小增加,如下面的屏幕截图.但是,我无法看到复选框..如何解决这个问题?

android android-preferences checkboxpreference listpreference