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

Ale*_*lex 9 customization android themes preferences

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

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

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

ste*_*ter 21

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

通过XML:

<Preference
android:key="Settings_CustomBG"
android:title="@string/Custom_BG"
android:widgetLayout="@layout/ic_custom"
/>
Run Code Online (Sandbox Code Playgroud)

或以编程方式:

   Preference BGColor = findPreference("Setting_BG_Color"); 
   BGColor.setWidgetLayoutResource(R.layout.ic_custom);
Run Code Online (Sandbox Code Playgroud)

其中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"
/>
Run Code Online (Sandbox Code Playgroud)

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

Android首选项中自定义窗口小部件布局的示例

  • @NunoGonçalves实际上很容易.只需使用android:icon.<首选安卓android:icon ="@ drawable/facebook_icon"android:key ="facebook_main"android:summary ="@ string/main_facebook_text"android:title ="@ string/main_facebook_title"/> (2认同)

Kev*_*oil 0

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