0

I would like to know how to customize theme/style of AlertDialog using sdk api 10. I know how to do that from 11 onwards but not how to do it on the 10.

XML Layout file

<?xml version="1.0" encoding="utf-8"?> <ScrollView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/scrollView" android:layout_width="match_parent" android:layout_height="wrap_content" android:padding="5dp" style="@style/dialog_theme" > <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical"> <TextView android:id="@+id/disclaimerText" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="@string/disclaimer" android:padding="5dp"/> <CheckBox android:id="@+id/checkDisclaimer" style="?android:attr/textAppearanceMedium" android:layout_width="match_parent" android:layout_height="wrap_content" android:padding="5dp" android:text="@string/agree" /> </LinearLayout> </ScrollView> 

JAVA Resource file

AlertDialog.Builder builder = new AlertDialog.Builder(this); //Setting Dialog Title builder.setTitle("Disclaimer"); //Setting Dialog Message builder.setMessage(R.string.disclaimer); View view = (View) LayoutInflater.from(this).inflate(R.layout.layout_disclaimer, null); builder.setView(view); 

1 Answer 1

1

You could try this:

View myView = View.inflate(this, R.layout.customize_dialog, null); AlertDialog.Builder builder=new AlertDialog.Builder(this); builder.setView(myView); builder.setTitle("Customize dialog"); builder.setCancelable(false); AlertDialog alert=builder.create(); alert.show(); 

You have to create a layout in res/layout/ called customize_dialog.xml, you can also add to "myView" other view object.

To add tipical Alert button:

builder.setPositiveButton("Ok",new OnClickListener(){ public void onClick(DialogInterface dialog, int id){ //action to do dialog.dismiss(); } }); builder.setNegativeButton("Close",new OnClickListener(){ public void onClick(DialogInterface dialog, int id){ //action to do dialog.dismiss(); } }); 

I hope it helps you.

Sign up to request clarification or add additional context in comments.

1 Comment

I have already created a custom layout and I added to the dialog but the issue continues to be different, in my layout I added style = "@ style / dialog_theme" but no, I still see the layout of the system. I have edited my answer

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.