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遇到的问题】五、最终效果:
推荐阅读
- SpringBoot调用公共模块的自定义注解失效的解决
- python自定义封装带颜色的logging模块
- 列出所有自定义的function和view
- Spring|Spring Boot 自动配置的原理、核心注解以及利用自动配置实现了自定义 Starter 组件
- 自定义MyAdapter
- Android自定义view实现圆环进度条效果
- Flutter自定义view|Flutter自定义view —— 闯关进度条
- js保留自定义小数点
- django|django 自定义.save()方法
- android-面试|我经历的IT公司面试及离职感受