Android-自定义圆角Dialog遇到的问题

一、自定义Dialg样式
layout.xml


shape:

二、自定义Dialog:
public class NoMoreFoucsDialog extends Dialog {private Context context; private ClickListenerInterface clickListenerInterface; public interface ClickListenerInterface { public void doConfirm(); public void doCancel(); }public NoMoreFoucsDialog(Context context) { super(context); this.context = context; }@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); init(); }public void init() { LayoutInflater inflater = LayoutInflater.from(context); View view = inflater.inflate(R.layout.layout_buzaiguanzhu, null); setContentView(view); TextView tvTitle = (TextView) view.findViewById(R.id.title); TextView tvConfirm = (TextView) view.findViewById(R.id.sure); TextView tvCancel = (TextView) view.findViewById(R.id.cancel); tvConfirm.setOnClickListener(new clickListener()); tvCancel.setOnClickListener(new clickListener()); Window window = getWindow(); WindowManager.LayoutParams params = window.getAttributes(); params.gravity = Gravity.CENTER; window.setAttributes(params); }public void setClicklistener(ClickListenerInterface clickListenerInterface) { this.clickListenerInterface = clickListenerInterface; }private class clickListener implements View.OnClickListener { @Override public void onClick(View v) { // TODO Auto-generated method stub int id = v.getId(); switch (id) { case R.id.sure: clickListenerInterface.doConfirm(); break; case R.id.cancel: clickListenerInterface.doCancel(); break; } } }}

三、遇到的问题:
这样的dialog没有圆角效果。
四、问题解决:
1、定义一个dialog的style:
name="MyDialogStyle" parent="@android:style/Theme.Dialog" > @null true true true @android:color/transparent @android:color/transparent true 0.6

2、在构造方法上去调用父类的带有style的构造方法:
public NoMoreFoucsDialog(Context context,int style) { super(context,style); this.context = context; }

【Android-自定义圆角Dialog遇到的问题】五、最终效果:

    推荐阅读