虽然现在流行DialogFragment但是有时候直接用AlertDialog感觉代码更少;
private void showTDialog(int contentId) {
View view = LayoutInflater.from(this).inflate(R.layout.dialog_layout_prompt, null, false);
final AlertDialog dialog = new AlertDialog.Builder(this).setView(view).create();
TextView content = view.findViewById(R.id.dialog_layout_prompt);
content .setText(contentId);
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
dialog.show();
}
圆角的关键是两个地方:
- 圆角背景:使用shape做一个圆角背景就好了
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#FFFBFB"/>
<corners android:radius="20dp"/>
</shape>
- window背景透明
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));