user2627142
user2627142

Reputation: 23

how to change .setpositive button and .setnegative button defualt theme color in android

In customize alert dialog I had included .setPositive and .setNegative buttons I want to change the default theme color to white color how? answers please. I don't want setOnClick color answer. code snippet below

Advance thanks regards mysmax

Upvotes: 1

Views: 247

Answers (2)

Cam Connor
Cam Connor

Reputation: 1231

Sorry if this isnt the answer your looking for but this is how you do it....

That is a default alert dialogue which I dont think you can customize, you will have to make a custom alert dialogue like this.

Define these as global variables

AlertDialog alertDialog;
View promptsView;
AlertDialog.Builder alertDialogBuilder;

add below to whatever causes the alertdialogue to appear

 LayoutInflater li = LayoutInflater.from(this));

    View promptsView = li.inflate(R.layout.CustomLayout, null);
    // above I am setting the customview of the alert dialogue


    AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(
            getActivity());

    alertDialogBuilder.setView(promptsView);
    // here I am officially setting the custom layout

    // set dialog message

    alertDialogBuilder.setTitle("Stretch Type");
    // alert dialogue title

    // create alert dialog
    alertDialog = alertDialogBuilder.create();

and for you CustomLayout.xml file just add a textview and two buttons one saying yes the other saying no or whatever you want them to say

Upvotes: 0

Vrashabh Irde
Vrashabh Irde

Reputation: 14367

Do it like this, but do alert.show() first and then change colour.

    AlertDialog.Builder builder = new AlertDialog.Builder(this);
            builder.setMessage("Stackoverflow answer!")
            .setPositiveButton("YES", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    dialog.cancel();
                }
            })
            .setNegativeButton("NO", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    dialog.cancel();
                }
            });
            AlertDialog alert = builder.create();
            alert.show();
//Use R.id.button1 and button2 
    ((Button)alert.findViewById(android.R.id.button1)).setBackgroundResource("Set to what you want");

Upvotes: 1

Related Questions