Reputation: 5717
I have PreferenceActivity with some sample content:
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<PreferenceCategory
android:title="First Category"
android:key="first_category">
<CheckBoxPreference
android:key="perform_updates"
android:summary="Enable or disable data updates"
android:title="Enable updates"
android:defaultValue="true"
/>
<ListPreference
android:key="updates_interval"
android:title="Updates interval"
android:summary="Define how often updates will be performed"
android:defaultValue="1000"
android:entries="@array/updateInterval"
android:entryValues="@array/updateIntervalValues"
android:dependency="perform_updates"
/>
</PreferenceCategory>
<PreferenceCategory
android:title="Second Category"
android:key="second_category">
<EditTextPreference
android:key="welcome_message"
android:title="Welcome Message"
android:summary="Define the Welcome message to be shown"
android:dialogTitle="Welcome Message"
android:dialogMessage="Provide a message"
android:defaultValue="Default welcome message"/>
</PreferenceCategory>
</PreferenceScreen>
As all of you know, it's looking incredibly ugly in all Androids before 4.0. Now the idea is to create custom theme and apply it to the activity. I want to make the ListView look like on the picture below:
I can adjust the separators ("Personalizacja", "Informacje[...]") by overriding <item name="listSeparatorTextViewStyle">
... but the real question is: how do I create such background with rounded corners for separate groups? I'm not able to find out any way to set custom style to first/last element in the group.
I'd be thankful for any ideas. But please note that I want to achieve it via styles & themes only.
btw. If you have an idea how to achieve the above, but without rounded corners - let me know too!
Upvotes: 1
Views: 1404
Reputation: 10352
I think the effect can be achieved for an android ListView. The main feature of the ListView is to recycle its row entries so that they don't have to be instantiated for every list entry.
The trick is to create multiple list element layouts and to swap them in in your ListAdapater. So you would basically have list entry for the group header, the group top element, the group middle elements and the group bottom element. All in all 4 different layout "templates" that your ViewHolder in your adapter should hold on to.
The following image describes the different layout segments:
Upvotes: 1
Reputation: 8390
Your limitation to styles & themes only is a very strict constraint, I'm 99% sure this is unachievable, since PreferenceScreen
uses its own ListView
, which you cannot customize using styles nor themes.
However, you may define android:widgetLayout
attribute for every item in your PreferenceScreen, where you will provide different background for different items depending on their position in the group.
Also, Android styles and layouts files, located at android-sdk-windows/platforms/android-xx/data/res/
, worth having a look in your case.
Upvotes: 1
Reputation: 180
You can Set background color in parent layout and use background image with round corner in listview. You can get some from code given below
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background="#your cloue code for main bg" >
<ListView
android:id="@+id/yourid"
android:background="@drawable/your bg with round corner"
android:cacheColorHint="#00000000"
android:layout_width="fill_parent"
android:layout_marginLeft="8dip"
android:layout_marginTop="0dip"
android:layout_marginRight="8dip"
android:layout_height="wrap_content"
android:textColor="#000000" >
</ListView>
</LinearLayout>
Upvotes: 0