Android的定制DialogFragment定制正/负按键设计 [英] Android custom DialogFragment custom positive/negative button design

查看:127
本文介绍了Android的定制DialogFragment定制正/负按键设计的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个自定义DialogFragment(支持库)。我设置的布局@色/ GhostWhite,问题是,我无法找到一个方法来设置相同颜色的正/负键。

这是我设置的按钮:

  builder.setView(视图)
    //添加动作按钮
           .setPositiveButton(呼!,新DialogInterface.OnClickListener(){
               @覆盖
               公共无效的onClick(DialogInterface对话,诠释的id){
                   //publishStory(/*shoutText.getText().toString()\"woww);
                   mListener.onDialogPositiveClick(WagDialogFragment.this);
               }
           })
           .setNegativeButton(R.string.cancel,新DialogInterface.OnClickListener(){
               公共无效的onClick(DialogInterface对话,诠释的id){
               }
           });    返回builder.create();


解决方案

您可以致电 getButton DialogInterface.BUTTON_POSITIVE DialogInterface.BUTTON_NEGATIVE 改变两个按钮的颜色参数:

 按钮okButton = alertDialog.getButton(DialogInterface.BUTTON_POSITIVE);
//设置OK按钮的颜色在这里
okButton.setBackgroundColor(R.color.GhostWhite);按钮noButton = alertDialog.getButton(DialogInterface.BUTTON_NEGATIVE);
//设置任何按钮颜色这里
noButton.setBackgroundColor(R.color.GhostWhite);

I have a custom DialogFragment (support library). I set the layout as @color/GhostWhite, problem is, I can't find a way to set the positive/negative button in the same color.

This is how I set the buttons:

        builder.setView(view)
    // Add action buttons
           .setPositiveButton("Shout!", new DialogInterface.OnClickListener() {
               @Override
               public void onClick(DialogInterface dialog, int id) {
                   //publishStory(/*shoutText.getText().toString()"woww");
                   mListener.onDialogPositiveClick(WagDialogFragment.this);
               }
           })
           .setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
               public void onClick(DialogInterface dialog, int id) {
               }
           });  

    return builder.create();

解决方案

you can call getButton with DialogInterface.BUTTON_POSITIVE and DialogInterface.BUTTON_NEGATIVE parameters for changing color of both buttons as:

Button okButton = alertDialog.getButton(DialogInterface.BUTTON_POSITIVE);
// set OK button color here
okButton.setBackgroundColor(R.color.GhostWhite);

Button noButton = alertDialog.getButton(DialogInterface.BUTTON_NEGATIVE);
// set NO button color here
noButton.setBackgroundColor(R.color.GhostWhite);

这篇关于Android的定制DialogFragment定制正/负按键设计的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆