android 封装dialog,android 快速开发-Dialog的简单封装

先看效果

3704563fc953

dialog.gif

使用方法:

step1:Add it in your root build.gradle at the end of repositories:

allprojects {

repositories {

...

maven { url 'https://jitpack.io' }

}

}

step2:Add the dependency

dependencies {

compile 'com.github.ithedan:BaseDialog:1.0'

}

Activity中使用:

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

Button bottom = (Button) findViewById(R.id.bottom_top);

Button top = (Button) findViewById(R.id.top_bottom);

Button left = (Button) findViewById(R.id.left_right);

Button right = (Button) findViewById(R.id.right_left);

Button center = (Button) findViewById(R.id.center);

Button center1 = (Button) findViewById(R.id.center1);

bottom.setOnClickListener(this);

top.setOnClickListener(this);

left.setOnClickListener(this);

right.setOnClickListener(this);

center.setOnClickListener(this);

center1.setOnClickListener(this);

}

private void showDialog(int grary, int animationStyle) {

BaseDialog.Builder builder = new BaseDialog.Builder(this);

final BaseDialog dialog = builder.setViewId(R.layout.photo_choose_dialog)

.setPaddingdp(10, 0, 10, 0)//设置dialogpadding

.setGravity(grary)//设置显示位置

.setAnimation(animationStyle)//设置动画

.setWidthHeightpx(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT)//设置dialog的宽高

.isOnTouchCanceled(true)//设置触摸dialog外围是否关闭dialog

.addViewOnClickListener(R.id.but_choose_one, new View.OnClickListener() {

@Override

public void onClick(View v) {

Toast.makeText(MainActivity.this,"相册", Toast.LENGTH_SHORT).show();

}

})//设置监听事件

.builder();

dialog.show();

Button button = dialog.getView(R.id.but_choose_three);//根据id获取dialog中的恐惧

button.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View v) {

dialog.close();

}

});//关闭dialog

}

@Override

public void onClick(View v) {

switch (v.getId()) {

case R.id.bottom_top:

showDialog(Gravity.BOTTOM, R.style.Bottom_Top_aniamtion);

break;

case R.id.top_bottom:

showDialog(Gravity.TOP, R.style.Top_Bottom_aniamtion);

break;

case R.id.left_right:

showDialog(Gravity.CENTER, R.style.Left_Right_aniamtion);

break;

case R.id.right_left:

showDialog(Gravity.CENTER, R.style.Right_Left_aniamtion);

break;

case R.id.center:

showDialog(Gravity.CENTER, R.style.Alpah_aniamtion);

break;

case R.id.center1:

showDialog(Gravity.CENTER, R.style.Scale_aniamtion);

break;

}

}

在BaseDialog:1.0中默认定义了以上六种动画效果,如果达不到项目要求可以根据自己的需求在style中自己定义,调用builder.setAnimation(int styleAnimation) 即可,dialog中默认的styles是:

@null

true

true

true

@android:color/transparent

@android:color/transparent

0.5

true

如果不符合要求可以调用builder.setStyle(int themeResId)设置自己的style;

dialog封装主要是为了项目中有多个dialog,不需要每个自定义dialog都要重写,有一个BaseDialog就够用了,如有什么问题,敬请提出,十分感谢!希望越来越好,谢谢!如果喜欢,还请点击start,喜欢支持一下了,谢谢O(∩_∩)O~

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值