我已经在我的应用程序中自定义了所有的radioButtons,但listPreference中的radioButtons没有自定义.
我使用了这个名为btn_radio.xml的xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_checked="true" android:state_window_focused="false"
android:drawable="@drawable/radio_selected" />
<item android:state_checked="false" android:state_window_focused="false"
android:drawable="@drawable/radio_unselected" />
<item android:state_checked="true" android:state_pressed="true"
android:drawable="@drawable/radio_selected" />
<item android:state_checked="false" android:state_pressed="true"
android:drawable="@drawable/radio_unselected" />
<item android:state_checked="true" android:state_focused="true"
android:drawable="@drawable/radio_selected" />
<item android:state_checked="false" android:state_focused="true"
android:drawable="@drawable/radio_unselected" />
<item android:state_checked="false" android:drawable="@drawable/radio_unselected" />
<item android:state_checked="true" android:drawable="@drawable/radio_selected" />
</selector>
Run Code Online (Sandbox Code Playgroud)
这是customRadioButton,它扩展了android自定义单选按钮
<style name="CustomRadioButton" Parent="@android:style/Widget.CompoundButton.RadioButton">
<item name="android:button">@drawable/btn_radio</item>
</style>
Run Code Online (Sandbox Code Playgroud)
在我的应用程序的主题中,我做了这个改变
<item name="android:radioButtonStyle">@style/CustomRadioButton</item>
<item name="android:listChoiceIndicatorSingle">@style/CustomRadioButton</item>
Run Code Online (Sandbox Code Playgroud)
此更改会自定义我的应用程序中的所有radioButtons,但ListPreference中的radioButtons除外
如何从Java端为ListPreference创建动态数组.
我不要使用Xml以下.
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string-array name="listArray">
<item>Value 1</item>
<item>Value 2</item>
<item>Value 3</item>
</string-array>
<string-array name="listValues">
<item>1</item>
<item>2</item>
<item>3</item>
</string-array>
</resources>
Run Code Online (Sandbox Code Playgroud) 我的xml目录中有user_preferences.xml.PreferencesActivity使用此文件来创建用户首选项活动..这样可行.用户在此处选择的内容仍然存在.但我无法检索用户选择的值.
当我用...
SharedPreferences preferences = getSharedPreferences("user_preferences.xml", 0);
String mapTypeString = preferences.getString("map_type_pref_key", "DEFAULT");
Run Code Online (Sandbox Code Playgroud)
... mapTypeString始终为"DEFAULT".
当我实例化我的SharedPreferences对象时,似乎找不到我的user_preferences.xml.但是,PreferencesActivity当然会找到它.那么,我错过了什么?
非常感谢!
我在我的应用程序中有listpreference,我想自定义它,我可以将主题设置为prefs活动如下:
<activity
android:name=".Prefs"
android:label="@string/app_name"
android:theme="@style/PreferencesTheme">
Run Code Online (Sandbox Code Playgroud)
偏好风格:
<?xml version="1.0" encoding="utf-8" ?>
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="PreferencesTheme" parent="android:Theme">
<item name="android:background">#FFDAB9</item>
<item name="android:textColor">@color/red_color</item>
<item name="android:textSize">20sp</item>
</style>
</resources>
Run Code Online (Sandbox Code Playgroud)
上面的样式更改了ListPreference背景和ListPreference标题文本大小和文本颜色,但它不会以任何方式更改ListPreference摘要文本颜色或大小,
我尝试了这段代码,但它不起作用:
<item name="android:textColorSecondary">@color/red_color</item>
Run Code Online (Sandbox Code Playgroud)
任何帮助将不胜感激,谢谢
我正在努力在触摸(选择)首选项时添加涟漪效果.我通过扩展来定制我的偏好ListPreference.我试图通过编程方式设置涟漪效果,RippleDrawable但我没有看到动画.
这是我的自定义偏好类
public class CustomListPreference extends ListPreference {
public CustomListPreference(Context context, AttributeSet attrs) {
super(context, attrs);
}
public CustomListPreference(Context context) {
super(context);
}
@Override
protected void onBindView(View view) {
super.onBindView(view);
setCustomStyle(view);
}
private void setCustomStyle(View view) {
TextView titleView = (TextView) view.findViewById(android.R.id.title);
titleView.setTypeface(InitActivity.TYPEFACE_REGULAR);
TextView summary = (TextView) view.findViewById(android.R.id.summary);
summary.setTypeface(InitActivity.TYPEFACE_REGULAR);
//Setting the drawable here, but it doesn't work.
RippleDrawable drawable = (RippleDrawable) getContext().getResources().getDrawable(R.drawable.my_ripple_background);
view.setBackGround(drawable);
}
}
Run Code Online (Sandbox Code Playgroud)
我的喜好布局
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<!-- opens a subscreen of …Run Code Online (Sandbox Code Playgroud) 这是我的代码:
它们如何不同以及哪些值会显示在对话框中?
<ListPreference
android:entryValues="@array/level"
android:entries="@array/level"
android:key="pref_numberOfChoices"
android:persistent="true"
android:summary="@string/level_description"
android:title="@string/level_title"
android:defaultValue="3"/>
Run Code Online (Sandbox Code Playgroud) 在Android上实现多选(Checkset)ListPreference的任何想法?
我是否必须扩展ListPreference?
是否有任何课程已经记录在案?
谢谢
如果将首选项的可选择性设置为false,您将注意到该项目周围的分隔符将消失.
你知道是否有办法保留这些分隔线?
我查看了ListView API,找不到可以在这里应用的解决方案,因为ListView项目没有可选属性(页眉和页脚除外).
谢谢!
android listview preferenceactivity listpreference android-listview
一个附接的挑战GestureDetector到ListPreference是2倍:
是否可以将GestureDetector附加到ListPreference?
如果是这样,怎么会这样呢?我在哪里编写代码来实例化GestureDetector并实现监听器?
我需要创建一个自定义ListPreference对话框,以便我可以在List(ListView)上方添加一些标题文本(TextView).我创建了MyListPreference类,它扩展了ListPreference并覆盖了onCreateDialogView():
@Override
protected View onCreateDialogView() {
LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View v = (View) inflater.inflate(R.layout.dialog_preference_list, null);
return v;
}
Run Code Online (Sandbox Code Playgroud)
我的XML布局dialog_preference_list.xml包含:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
<ListView
android:id="@android:id/list"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawSelectorOnTop="false"
android:scrollbarAlwaysDrawVerticalTrack="true" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
问题:TextView显示在ListView下面而不是上面.我需要TextView在上面.我已尝试使用LinearLayout和RelativeLayout(使用"下方"或"上方"属性)但没有成功:我找不到将TextView放在ListView上方的方法...布局非常简单,我看不到为什么列表保持在上面...另外,请注意问题发生在真实设备(Nexus 4,Android 4.2.2)和模拟器上.但是,在查看Eclipse的图形布局中呈现的布局时,布局是正确的!查看附图.
关于如何解决这个问题的任何想法?
在设备上呈现的布局(不正确):

在Eclipse上呈现的布局(正确):

使用解决方案10.07.2013进行编辑
正如接受的答案所暗示的那样,问题来自在ListPreference的onPrepareDialogBuilder()中使用builder.setSingleChoiceItems().我通过扩展ListPreference并覆盖onCreateDialogView()来修复它,以构建没有构建器的Dialog,这样我就可以创建一个自定义视图,显示列表项上方的标题文本.
GPListPreference.java:
public class GPListPreference extends ListPreference {
...
@Override
protected void onPrepareDialogBuilder(AlertDialog.Builder builder) {
builder.setNegativeButton(null, null);
builder.setPositiveButton(null, null);
}
private int getValueIndex() {
return findIndexOfValue(getValue());
}
@Override …Run Code Online (Sandbox Code Playgroud) android ×10
listpreference ×10
arrays ×1
dynamic ×1
listview ×1
preferences ×1
radio-button ×1