自定义的 Dialog 只支持Androidx
Step 1. Add it in your root build.gradle at the end of repositories:
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
Step 2. Add the dependency
dependencies {
implementation 'com.github.hongInBlack:ExdDialog:1.0.2'
}
<item name="exDialogStyle">@style/ExDialogStyle</item>
<style name="ExDialogStyle">
<item name="exdTheme">@style/ExdStyle</item>
<item name="exdPositiveTextSelector">@color/color_blue_text</item>
<item name="exdNegativeTextSelector">@color/color_blue_text</item>
<item name="exdPositiveBgSelector">@drawable/dialog_selector</item>
<item name="exdNegativeBgSelector">@drawable/dialog_selector</item>
<item name="exdListItemColor">@color/exd_black</item>
<item name="exdSheetItemColor">#287de8</item>
<item name="exdNegativeText">取消</item>
<item name="exdPositiveText">确定</item>
<item name="exdSheetCancelText">这是sheet取消</item>
</style>
new ExDialog.Builder(this)
.autoDismiss(true)
.title("温馨提示")
.content("明日天气:东风有雨,明日天气:东风有雨,明日天气:东风有雨,明日天气:东风有雨,明日天气:东风有雨。")
.onAction((dialog,isOk) -> showToast(isOk + "!"))
.build()
.show();
new ExDialog.Builder(this)
.autoDismiss(true)
.title("温馨提示")
.onAction((dialog,isOk) -> showToast(isOk + "!"))
.build()
.show();
ExDialog.Builder.newInstance(this)
.autoDismiss(true)
.title("温馨提示")
.content("明日天气:东风有雨")
.singleAction()
.onAction((dialog,isOk) -> showToast(isOk + "!"))
.build()
.show();
ExDialog.Builder.newInstance(this)
.autoDismiss(true)
.title("温馨提示")
.content("明日天气:东风有雨")
.negativeText("淡定淡定淡定淡定 淡定淡定淡定淡定 淡定淡定淡定淡定 淡定淡定淡定 淡定淡定淡定淡定 淡定淡定淡定淡定")
.positiveText("打伞")
.contentColorRes(R.color.exd_sheet_cancel_text)
.negativeColor(getResources().getColor(R.color.colorPrimary))
.positiveColor(getResources().getColor(R.color.exd_black))
.onAction((dialog,isOk) -> showToast(isOk + "!"))
.build()
.show();
ExDialog.Builder.newInstance(this)
.autoDismiss(true)
.title("成功")
.content("设备已经更新")
.iconRes(R.drawable.icon_success)
.singleAction()
.onAction((dialog,isOk) -> showToast(isOk + "!"))
.build()
.show();
ExDialog.Builder.newInstance(this)
.autoDismiss(true)
.title("请输入密码")
.content("长度大于等于10位")
.inputTypeTextPassWord()
.input("请输入密码",(dialog,input) -> {
if (input.toString().trim().length() >= 10 || input.toString().trim().length() == 0) {
dialog.positiveView().setEnabled(true);
} else {
dialog.positiveView().setEnabled(false);
}
})
.onAction((dialog,isOk) -> {
if (isOk) {
showToast(dialog.positiveView().getText() + "!");
} else {
showToast("取消!");
}
})
.build()
.show();
new ExDialog.Builder(this)
.autoDismiss(true)
.negativeBg(null)
.positiveBg(null)
.customView(R.layout.coustom,true)
.onAction((dialog,isOk) -> showToast(isOk + "!"))
.build()
.show();
ArrayList<String> list = new ArrayList<>();
for (int i = 0; i < 1; i++) {
list.add("苹果");
list.add("菠萝");
list.add("西瓜");
}
List<Integer> colors = new ArrayList<>();
for (int i = 0; i < list.size(); i++) {
colors.add(Color.BLACK);
}
colors.set(0,Color.parseColor("#DB4437"));
colors.set(2,Color.parseColor("#86B950"));
new ExDialog.Builder(this)
.list(list)
.title("水果种类")
.content("你好,欢迎你,请您选择您喜欢吃的水果,如果觉得满意,请给五星好评!")
.itemColors(colors)
// .selectPosition(0)
.listItemTextColorRes(R.color.exd_dialog_blue)
.onItemClick((dialog,position) -> showToast(list.get(position)))
.build()
.show();
ArrayList<String> list = new ArrayList<>();
list.add("苹果");
list.add("菠萝");
list.add("西瓜");
list.add("鸭梨");
List<Integer> colors = new ArrayList<>();
for (int i = 0; i < list.size(); i++) {
colors.add(Color.BLACK);
}
colors.set(0,Color.parseColor("#DB4437"));
colors.set(2,Color.parseColor("#86B950"));
new ExDialog.Builder(this)
.sheet(list)
.itemColors(colors)
.onItemClick((dialog,position) -> showToast(list.get(position)))
.build()
.show();