0

我在这里查看文档:http: //developer.android.com/guide/topics/ui/dialogs.html#PassingEvents

他们所有的例子似乎都忽略了开发人员完全改变 OK | 外观和/或定位的潜在愿望。取消按钮。

我觉得 DialogFragment 的解决方案很接近,但我仍然没有明显的方法来定义我的活动中的 View 应该是 OK 按钮,以便我可以轻松地将回调附加到它。

我错过了什么?还是真的不可能在任何扩展 AlertDialog 或 DialogFragment 的东西中操纵按钮的外观和位置?

4

1 回答 1

2

您可以使用Dialog并向其添加自己的自定义布局,并控制其中每个视图的外观。这是一个如何执行此操作的示例:

final Dialog alert = new Dialog(FingerPaintActivity.this, android.R.style.Theme_Light_Panel);
alert.requestWindowFeature(Window.FEATURE_NO_TITLE); // no title 
alert.getWindow().getAttributes().windowAnimations = R.style.PauseDialogAnimation; // this is used for custom animation when dialog is showing and hiding 
alert.setContentView(getLayoutInflater().inflate(R.layout.stamps, null)); // here is your custom layout
alert.getWindow().setLayout(width-50, (height-100)); // set height / width

您可以像这样对视图(例如按钮)使用设置侦听器:

Button myOkBtn = (Button) alert.findViewById(R.id.myOkBtn);
myOkBtn.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {

        }
    });
于 2013-02-06T20:27:56.423 回答