Android开源库-BottomDialog两种样式弹框
Posted 雪の星空朝酱
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Android开源库-BottomDialog两种样式弹框相关的知识,希望对你有一定的参考价值。
android开源库-BottomDialog两种样式弹框
关于
网上这种底部弹窗一大堆,写这个开源library主要还是自己后面项目集成使用方便。。仓库地址
效果图(目前仅两种dialog,后续会增加)
添加引用
allprojects
repositories
maven url 'https://jitpack.io'
dependencies
implementation 'com.github.Tobeyr1:libBottomDialog:1.0.0-alpha'
使用
这里只介绍java 版使用方法,kotin版使用可以在github的app里面看到(正常使用):
BottomAlertDialog dialog = new BottomAlertDialog()
.openFullScreenMask(false,R.color.color_transparent,0.1f) //是否开启全屏以及弹框透明度,设置true则无法修改dialog位置,仅限底部使用
.setBackGroundColor(R.color.white)
.setContent("Exiting out of this form will remove all record information. Would you like to exit anyway?")
.setConfirmBg(R.drawable.bg_button_full_green_408)
.setCancelBg(R.drawable.bg_button_login_full_border_black_stroke_2)
.setTitle("Java title")
//.setCancelBtnGone() //是否隐藏取消按钮
.setTitleColor(R.color.black)
.setGravityStyle(Gravity.BOTTOM)
.setCanceledOnTouchOutside(false)
.setPositiveButtonMethod("Ok",R.color.white,(d,view) ->
d.dismiss();
return null;
)
.setNegativeButtonMethod("Cancel",R.color.black,(d,view) ->
d.dismiss();
return null;
)
.setFragmentManager(getSupportFragmentManager())
;
dialog.show();
BottomChoiceDialog bottomChoiceDialog = new BottomChoiceDialog(
arrayList,(position,value) ->
switch (position)
case 0 :
Toast.makeText(this, "take photo", Toast.LENGTH_SHORT).show();
break;
case 1 :
Toast.makeText(this, "Select from library", Toast.LENGTH_SHORT).show();
break;
case 2 :
Toast.makeText(this, "View image full Screen", Toast.LENGTH_SHORT).show();
break;
return null;
);
bottomChoiceDialog.show(getSupportFragmentManager(),"dialog");
中间圆角样式
BottomAlertDialog dialog = new BottomAlertDialog()
.openFullScreenMask(false, R.color.color_transparent,0.1f)
.setBackGroundColor(R.drawable.bg_dialog_full_radius_14_white)
.setContent("Exiting out of this form will remove all record information. Would you like to exit anyway?")
.setConfirmBg(R.drawable.bg_button_full_green_408)
.setCancelBg(R.drawable.bg_button_login_full_border_black_stroke_2)
.setTitle("Java title")
.setTitleColor(R.color.black)
.setGravityStyle(Gravity.CENTER)
.setCanceledOnTouchOutside(false)
.setWidth(getScreenWidth()-dpToPx(32))//单独设置宽度
//.setWindowSize(getScreenWidth()-dpToPx(32),dpToPx(280)) //整体size
.setPositiveButtonMethod("Ok",R.color.white,(d,view) ->
d.dismiss();
return null;
)
.setNegativeButtonMethod("Cancel",R.color.black,(d,view) ->
d.dismiss();
return null;
)
.setFragmentManager(getSupportFragmentManager())
;
dialog.show();
private int getScreenWidth()
return getResources().getDisplayMetrics().widthPixels;
private int getScreenHeight()
return getResources().getDisplayMetrics().heightPixels;
private int dpToPx(int dp)
return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,dp,getResources().getDisplayMetrics());
中间圆角+弹窗阴影效果
BottomAlertDialog dialog = new BottomAlertDialog()
.openFullScreenMask(false, R.drawable.bg_dialog_full_radius_14_white,0.1f)//同时使用圆角shape
.setBackGroundColor(R.drawable.bg_dialog_full_radius_14_white)
//.setCancelBtnGone() //是否隐藏取消按钮
.setContent("Exiting out of this form will remove all record information. Would you like to exit anyway?")
.setConfirmBg(R.drawable.bg_button_full_green_408)
.setCancelBg(R.drawable.bg_button_login_full_border_black_stroke_2)
.setTitle("Java title")
.setTitleColor(R.color.black)
.setGravityStyle(Gravity.CENTER)
.setCanceledOnTouchOutside(false)
.setWidth(getScreenWidth()-dpToPx(32))
//.setWindowSize(getScreenWidth()-dpToPx(32),dpToPx(280))
.setPositiveButtonMethod("Ok",R.color.white,(d,view) ->
d.dismiss();
return null;
)
.setNegativeButtonMethod("Cancel",R.color.black,(d,view) ->
d.dismiss();
return null;
)
.setFragmentManager(getSupportFragmentManager())
;
dialog.show();
bg_dialog_full_radius_14_white.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners android:radius="14dp" />
<solid android:color="#FFFFFF" />
</shape>
以上是关于Android开源库-BottomDialog两种样式弹框的主要内容,如果未能解决你的问题,请参考以下文章