java 带自定义按钮的对话框。标签:#android来自:https://stackoverflow.com/questions/4095758/change-button-color-in-ale

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了java 带自定义按钮的对话框。标签:#android来自:https://stackoverflow.com/questions/4095758/change-button-color-in-ale相关的知识,希望对你有一定的参考价值。

@Override
public Dialog onCreateDialog(final Bundle savedInstanceState) {
  AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());

  // setup your dialog here...

  builder.setNegativeButton(getString(R.string.cancel), new DialogInterface.OnClickListener() {
    @Override
    public void onClick(final DialogInterface dialog, final int which) {
      // do something
    }
  });

  builder.setPositiveButton(getString(R.string.ok), new DialogInterface.OnClickListener() {
    @Override
    public void onClick(final DialogInterface dialog, final int which) {
      // do something
    }
  });

  final AlertDialog dialog = builder.create();

  dialog.setOnShowListener(new DialogInterface.OnShowListener() {
    @Override
    public void onShow(final DialogInterface dialog) {
      Button negativeButton = ((AlertDialog)dialog).getButton(DialogInterface.BUTTON_NEGATIVE);
      Button positiveButton = ((AlertDialog)dialog).getButton(DialogInterface.BUTTON_POSITIVE);

      // this not working because multiplying white background (e.g. Holo Light) has no effect
      //negativeButton.getBackground().setColorFilter(0xFFFF0000, PorterDuff.Mode.MULTIPLY);

      final Drawable negativeButtonDrawable = getResources().getDrawable(R.drawable.alert_dialog_button_light_red);
      final Drawable positiveButtonDrawable = getResources().getDrawable(R.drawable.alert_dialog_button_light_green);
      if (Build.VERSION.SDK_INT >= 16) {
        negativeButton.setBackground(negativeButtonDrawable);
        positiveButton.setBackground(positiveButtonDrawable);
      } else {
        negativeButton.setBackgroundDrawable(negativeButtonDrawable);
        positiveButton.setBackgroundDrawable(positiveButtonDrawable);
      }

      negativeButton.invalidate();
      positiveButton.invalidate();
    }
  });

  return dialog;
}

以上是关于java 带自定义按钮的对话框。标签:#android来自:https://stackoverflow.com/questions/4095758/change-button-color-in-ale的主要内容,如果未能解决你的问题,请参考以下文章

WPS文字 JSA 学习笔记 - 转PDF后要带自定义目录

WPS文字 JSA 学习笔记 - 转PDF后要带自定义目录

WPS文字 JSA 学习笔记 - 转PDF后要带自定义目录

在角垫对话框中单击标签上的检查单选按钮

带自定义图标的Leaflet SuperCluster标记?

xml 带图像的模板数据Feed / Sitemap(带自定义图片网址结构)[MPS]