android自定义对话框怎么设置弧度

2025-05-18 04:12:39
推荐回答(1个)
回答(1):

我想你想要实现圆角的对话框,可以参考如下:

package com.example.jjy.myapplication;
import android.app.Dialog;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
/**
* Created by jjy on 16-5-15.
*/
public class MyDialog extends Dialog{
private Button positiveButton, negativeButton;
private TextView contenttv;

public MyDialog(Context context) {
super(context,R.style.mydialog);
View view = LayoutInflater.from(getContext()).inflate(R.layout.mydialoglayout, null); //通过LayoutInflater获取布局
contenttv = (TextView) view.findViewById(R.id.title);
positiveButton = (Button) view.findViewById(R.id.acceptbtn);
negativeButton = (Button) view.findViewById(R.id.refusebtn);
setContentView(view); //设置view
}
//设置内容
public void setContent(String content) {
contenttv.setText(content);
}
//确定按钮监听
public void setOnPositiveListener(View.OnClickListener listener){
positiveButton.setOnClickListener(listener);
}

//否定按钮监听
public void setOnNegativeListener(View.OnClickListener listener){
negativeButton.setOnClickListener(listener);
}
}

R.style.mydialog 对话框属性在 values/styles.xml中设置:

[html] view plain copy