如何自定义首选项屏幕主题看起来像那样?

时间:2011-01-15 12:10:11

标签: android themes preferences customization

好的,我有一个带有XML布局的Preferences活动集。 在这里,我有几个首选项打开一些对话框。根据这些偏好,我想在屏幕截图中右侧有一个箭头。我是怎么做到的,与主题有关吗? 第一个截图是我想要看的,第二个是我现在拥有的。

http://img545.imageshack.us/i/screenshot1zlk.png/

http://img405.imageshack.us/i/tsc3.png/

2 个答案:

答案 0 :(得分:21)

在您的偏好活动中,您可以设置您想要在每个首选项“widget_layout”(标题/摘要右侧的区域)中显示的内容,如下所示:

通过XML:

<Preference
android:key="Settings_CustomBG"
android:title="@string/Custom_BG"
android:widgetLayout="@layout/ic_custom"
/>

OR编程:

   Preference BGColor = findPreference("Setting_BG_Color"); 
   BGColor.setWidgetLayoutResource(R.layout.ic_custom);

ic_custom.xml(在/ layout中)是:

<?xml version="1.0" encoding="utf-8"?>
<ImageView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_custom"
/>

和ic_custom只是资源文件夹中的图像文件。在我的情况下,这看起来如下:

example of custom widget layout in an android preference

答案 1 :(得分:0)

这取决于Preference的类型。通用的“首选项”类型将显示为空白,CheckBoxPreference自然会显示CheckBox,对于您感兴趣的内容,DialogPreference(和子项)会显示箭头: http://developer.android.com/reference/android/preference/DialogPreference.html

相关问题