Is it possible to change background color of Preference

by Vincent » Tue, 16 Feb 2010 19:33:17 GMT


Sponsored Links
 Hi,

Does anybody know how to change the background color of Preference
(PreferenceCategory, EditTextPreference ...) ?

I wanna do like this:
<PreferenceCategory android:title="title_test"
android:background="@color/testColor">
But this doesn't work...
I searched these by using google, but couldn't find any right
answer...

Also, I couldn't find any way to change other layouts. (e.g. text
color, size and style of preference title or summary)
Is there no way to customize the layout of Preferences?
It'll be great if somebody can help me out.

thanks in advance!

--



Is it possible to change background color of Preference

by Bob Kerns » Wed, 17 Feb 2010 00:23:02 GMT


 I think you'll need to supply the android:layout attribute, and supply
an alternative layout with the background set.

You can find the default layout in the SDK at platforms/android-2.1/
data/res/layout/preference.xml

If you just want to customize the widget portion, use
android:widgetLayout instead, but this sounds like you want to affect
the entire preference.




--


Sponsored Links


Is it possible to change background color of Preference

by joebowbeer » Wed, 17 Feb 2010 05:51:28 GMT


 Something like this:

public class MyPreferenceActivity extends PreferenceActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
 
getWindow().setBackgroundDrawableResource(R.drawable.my_background);
        getListView().setBackgroundColor(Color.TRANSPARENT);
        getListView().setCacheColorHint(Color.TRANSPARENT);
        getPreferenceManager().setSharedPreferencesName("my_prefs");
        addPreferencesFromResource(R.xml.my_preferences);
    }

I'm not sure if the listView changes are necessary or advisable.

Joe




--



Is it possible to change background color of Preference

by skink » Wed, 17 Feb 2010 07:09:36 GMT


 



i'm afraid it works only for top-level preferences.

if you have inner ScreenPreferences it won't work as ScreenPreferences
use Dialogs in order to show their child Preferences

pskink

--



Is it possible to change background color of Preference

by Vincent » Wed, 17 Feb 2010 13:31:50 GMT


 Bob, joebowbeer, skink

Thanks so much for your help!!
I successfully managed to change the layout of preference.

As joebowbeer wrote, I changed the top-level background image and
listview setting in my code like below.
 
getWindow().setBackgroundDrawableResource(R.drawable.my_background);
        getListView().setBackgroundColor(Color.TRANSPARENT);
        getListView().setCacheColorHint(Color.TRANSPARENT);

Then, I supplied the custom layout to the android:layout attribute in
xml in order to change other child preferences as Bob stated.
    <PreferenceScreen xmlns:android=" http://schemas.android.com/apk/ 
res/android">
        <PreferenceCategory android:title="test_title"
android:layout="@xml/preference_category">
            <EditTextPreference
                android:key="edit_key"
                android:title="edit_title"
                android:summary="edit_summary"
                android:layout="@xml/preference"
                />
        </PreferenceCategory>
    </PreferenceScreen>


Thank you very much!!








--



Other Threads

1. Thin white line runs through the <Button> in disabled state.

I am using a <Button> widget in one of my layout. I created this
button in disabled state. A thin white line runs through the button,
at center horizontal,  while it is in disabled state. And in enabled
state it is normal like any other widgets.

Below is the layout code:
----------------------------------------------------------------------------------------------------------------------

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/
android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
<TextView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="@string/hello"
    />
    <Button
            android:id="@+id/my_button"
            android:layout_width="fill_parent"
            android:layout_height="45dp"
            android:text="@string/hello"
            android:enabled="false"
     />
</LinearLayout>
-------------------------------------------------------------------------------------------------------------------------------------

I am setting the height of the button as
                               android:layout_height="45dp".

When I set the height as  "wrap_content" this issue (white line on
disabled state) is not seen.

Any insight about this issue.

-- 

2. Is Usbnet driver (host) available for android2.2?

Hi,

Yes, USB net (host) driver is availailble for android, actually it is in
linux kernel before.
On host side, you config kernel to support USB net (in Network configuration
menu)
On device side, you config kernel to support USB gadget CDC ethernet (RNDIS)
(in USB driver configuration menu)
configure ip by : ifconfig usb0 <ip_address>

Cheer,




> website: 

3. wifi - dhcpcd/getprop problem.

4. Guide on adding WiFi drivers to Android

5. opnegl es 2.0 on the Froyo is working now?

6. Dynamic images slide show along with context menu and about smooth swipe event..Urgent suggestion/Idea needed..

7. Android and Proguard