0

I am working with checkBoxPreference from few days,

have figured out:

  1. how to display icon with checkBoxPreference,
  2. how to change colour of title and summary

Now, I need to add a button instead of the icon. So any one here has any ideas on this...

I have tried to add a button in onCreateView in the preferenceFragment but no luck... Can't add it in the xml as I am adding checkBoxPreference dynamically.

Thanks,

AliR
  • 2,065
  • 1
  • 27
  • 37

2 Answers2

0

When building a checkbox preference through xml we can set a custom layout where we can put whatever we like to achieve our desired result as given below:

    <CheckBoxPreference
    android:defaultValue="false"
    android:key="message_pop"
    android:layout="@layout/custom_checkbox_preference_layout"
    android:summary="Enable incoming message pop-up"
    android:title="Message Pop-up" />

I am not sure but may be this piece of code will help you

    CheckBoxPreference checkBoxPreference = new CheckBoxPreference(this);
    checkBoxPreference.setWidgetLayoutResource(R.layout.custom_checkbox);

to assign a custom layout to your dynamically create checkbox preference. In this custom layout you can use whatever views you want.

Prativa
  • 364
  • 6
  • 25
  • thanks but please read the question, I am adding the CheckBoxPreference dynamically - so no xml here. – AliR Jan 29 '13 at 04:38
  • @ali rajput, i have read the question. I was suggesting you to google a way to use custom layout in your checkbox dynamically – Prativa Jan 29 '13 at 04:39
  • :) I have googled it all, no luck thats why I posted a Question here. Thanks – AliR Jan 29 '13 at 04:45
  • Thanks for the hint, I previously avoided using custom layout as I got away with textColor for the title and displaying icon with an another way. Not finished yet but seems the button could be added only this way at the moment. – AliR Jan 29 '13 at 05:38
0

We need to define our own layout which can be used, using two lines mentioned by @Prativa, example of a good layout to add widgets to, can be seen at this link:

CheckBoxPreference with own layout

Furthermore, you would also need to write a custom checkBoxPreference class if you want to modify any of the properties of the widgets added to this custom layout.

Community
  • 1
  • 1
AliR
  • 2,065
  • 1
  • 27
  • 37