对话框上的黑色动作按钮

时间:2013-09-19 10:25:33

标签: android button background dialog

只是一个简单的问题。我创建了一个带有操作按钮的对话框(正面和负面)。但是动作按钮是浅色的。有没有一种简单的方法可以将它们变为黑暗?例如:

enter image description here

2 个答案:

答案 0 :(得分:2)

您可以将drawable分配给对话框的操作按钮。设计一个深色图像,然后将其分配给您的动作按钮,如下所示

Button actionBtn = dialog.getButton(DialogInterface.BUTTON_POSITIVE);

actionBtn.setBackgroundDrawable(getResources().getDrawable(R.drawable.dark_btn));

希望这有帮助。

答案 1 :(得分:0)

试试吧..

//final AlertDialog.Builder alertDialog = new AlertDialog.Builder(this);

    final AlertDialog.Builder alertDialog = new 
      AlertDialog.Builder(new ContextThemeWrapper(this,android.R.style.Theme_Dialog));

    // Setting Dialog Title
    alertDialog.setTitle("WorkGoal");
    alertDialog.setCancelable(false);

    // Setting Dialog Message
    alertDialog.setMessage("Click OK or Cancel");

    // On pressing Settings button
    alertDialog.setPositiveButton("ok", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog,int which) {
            alertDialog.setCancelable(true);
            dialog.cancel() ;
            Log.v("hari", "------After OK button clicked-----------");

        }
    });

    // on pressing cancel button
    alertDialog.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
        //dialog.cancel();
            alertDialog.setCancelable(true);
           dialog.cancel() ;
           Log.v("hari", "------After CANCEL button clicked-----------");


        }
    });

    // Showing Alert Message
    alertDialog.show();

  just refer this : http://stackoverflow.com/questions/8623948/
  how-to-apply-backround-color-and-theme-to-alert-dailog-builder