Android 弹窗工具库 PopupWindow 工具 ,自定义提示框
作者:互联网
gitHub 地址:https://github.com/inksnow/popuputils
build.gradle (Project)中添加 maven { url 'https://jitpack.io' }
allprojects {
repositories {
jcenter()
maven { url 'https://jitpack.io' }
}
}
build.gradle (app)中添加 implementation 'com.github.inksnow:popuputils:1.0.9'
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
.....
implementation 'com.github.inksnow:popuputils:1.0.9'
}
public void ccc(View view) {
switch (view.getId()){
case R.id.test:
TextView textView = new TextView(context);
textView.setText("这真是一个提示!");
textView.setTextColor(0XFF333333);
textView.setPadding(50,0,0,0);
ViewSettings.Builder builder = new ViewSettings.Builder();
ViewSettings promptSettings =
builder.clickListener(popupBackListener)
.titleTextStr("这是一个提示")
.focusable(false)
.outsideTouchable(false)
.build();
popupView.popupView(window,context,inflater,textView,promptSettings,1);
break;
case R.id.test2:
LinearLayout linearLayout = (LinearLayout) inflater.inflate(
R.layout.image_and_text, null);
builder = new ViewSettings.Builder();
promptSettings =
builder .clickListener(popupBackListener)
.showTitle(false)
.showButton1(false)
.popupBg(new int[] {0XFF03a9f4,0XFFFFFFFF})
.build();
popupView.popupView(window,context,inflater,linearLayout,promptSettings,2);
break;
case R.id.test3:
linearLayout = (LinearLayout) inflater.inflate(
R.layout.scrollviewtest, null);
builder = new ViewSettings.Builder();
promptSettings =
builder .clickListener(popupBackListener)
.titleTextStr("你好呀")
.titleIcon(getDrawable(R.mipmap.ic_launcher_round))
.titleTextPaddings(new int[]{10,20,0,20})
.showTitleIcon(true)
.build();
popupView.popupView(window,context,inflater,linearLayout,promptSettings,3);
break;
case R.id.test4:
textView = new TextView(context);
textView.setText("你确定要这样做吗?");
textView.setTextColor(0XFF333333);
textView.setGravity(Gravity.CENTER);
builder = new ViewSettings.Builder();
promptSettings =
builder .clickListener(popupBackListener)
.showTitle(false)
.showButton1(false)
.build();
popupView.popupView(window,context,inflater,textView,promptSettings,4);
break;
}
}
PopupView.onClickListener popupBackListener = new PopupView.onClickListener() {
@Override
public void onYesBack(int what) {
showMgs("你点击了提示框"+what+"确定按钮");
}
@Override
public void onCancelBack(int what) {
showMgs("你点击了提示框"+what+"取消按钮");
}
};
private void showMgs(String mgs){
popupPrompt.miss();
PromptSettings.Builder builder = new PromptSettings.Builder();
PromptSettings promptSettings = builder
.text(mgs)
.clippingEnabled(true)
.textPaddings(new int[]{50,0,0,0})
.location(Gravity.TOP)
.popupAnim(R.style.popup_top_down)
.bgAlpha(0.6f)
.build();
popupPrompt.popupPrompt(window,context,inflater,promptSettings,0);
}
//为了解决弹出PopupWindow后外部的事件不会分发,既外部的界面不可以点击
@Override
public boolean dispatchTouchEvent(MotionEvent event){
L.e("dispatchTouchEvent");
if (popupView.getpWindow()!= null && popupView.getpWindow().isShowing()){
L.e("popupSelect.getpWindow().isShowing()");
return false;
}else{
return super.dispatchTouchEvent(event);
}
}
标签:popupView,PopupWindow,自定义,builder,inflater,new,工具,textView,promptSettings 来源: https://blog.csdn.net/ink_s/article/details/95610972