问题
i have created a dialog box which has "accept" and "reject" buttons, but the color of the button is in default color. can anyone provide the code to set the color of the buttons in green and red.
回答1:
By creating a custom drawable.. for example..
button.setBackgroundResource(R.drawable.custom_button);
custom_button.xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item>
<shape android:shape="rectangle">
<corners android:radius="8dip" />
<stroke android:width="1dp" android:color="your color" />
<solid android:color="@color/ceruleo" />
</shape>
</item>
<item android:top="1dp" android:bottom="1dp" android:left="1dp" android:right="1dp">
<shape android:shape="rectangle">
<corners android:radius="8dip" />
<stroke android:width="1dp" android:color="your color" />
<solid android:color="@color/ceruleo" />
</shape>
</item>
</layer-list>
回答2:
Button b = dialog.getButton(DialogInterface.BUTTON_NEGATIVE);
if(b != null)
b.setBackgroundColor(Color.BLUE);
This Code will help you. You can set color to Negative or positive button as you wish.
回答3:
ANother way is , you can create dialogue activity for custom dialogues. just create activity and in manifest
android:theme="@android:style/Theme.Dialog
create layout for this. by this way you can create any design you want
来源:https://stackoverflow.com/questions/13701162/how-to-set-button-color-in-dialog-box