Custom View in Dialog

How to customize style in advanced DialogPreference?

public class AboutDialog extends DialogPreference { public AboutDialog(Context oContext, AttributeSet attrs) { super(oContext,attrs); //there is no such a thing like setBackground(int res_id)... } } 

and in xml

 <com.pak1.pak.About android:key="key" android:title="@string/preferences_about" android:dialogTitle="@string/preferences_about_title" android:dialogIcon="@drawable/app_icon" android:negativeButtonText="@null" android:positiveButtonText="@string/ok" /> 

or, for example, can I change the properties of a button?

I have one ok button, and for example, I want to change the color of this ok button, how can I do this?

+4
source share
2 answers

You will override onCreateDialogView and return the layout.

See, for example, this Matthew Wiggins example for creating a custom dialog box.

http://android.hlidskialf.com/blog/code/android-seekbar-preference

or here in stackoverflow

Android SeekBarPreference

+5
source

To set the DialogPreference background, you can also use the method

  DialogPreference.setDialogLayoutResource(R.layout.layout1); 

and simple color resources, usually set inside res/values/colors.xml :

  <color name="red">#ffff0000</color> 

Access this resource via android:background="@color/red" in res/layout/layout1.xml . ( More on background setting )

0
source

Source: https://habr.com/ru/post/1381123/


All Articles