Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to customize preferences screen theme to look like that?

Ok, I have a Preferences activity set with an XML layout. Here I have a couple of Preferences that open some dialogs. On these preferences I want to have an arrow on the right of them like in the screenshot. How I do this, is something related to the theme ? First screenshot is how I want to look, second is what I have now.

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

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

like image 870
Alex Avatar asked Jan 15 '11 12:01

Alex


1 Answers

In your preference activity you can set whatever you want to appear in each preferences "widget_layout" (the area to right of the title/summary) like so:

Via XML:

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

OR programatically:

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

Where ic_custom.xml (in /layout) is:

<?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"
/>

and ic_custom is just an image file in the resources folder(s). In my case this looks like the following:

example of custom widget layout in an android preference

like image 152
stealthcopter Avatar answered Oct 11 '22 04:10

stealthcopter