AnyDialog 使用说明
GitHub 主页
Android高定制性,高易用性Dialog。
简介
- 链式调用
- 一行代码实现背景高斯模糊
- 可自定义进出场动画
- 可自由控制显示大小和位置
下载
- Demo:下载
截图

使用说明
[站外图片上传中...(image-65ee9e-1526989685902)]
-
添加jitpack库
//build.gradle(Project:)
allprojects {
repositories {
...
maven { url 'https://www.jitpack.io' }
}
}
-
添加依赖
//build.gradle(Module:)
dependencies {
compile 'com.github.goweii:SwipeDragTreeRecyclerView:v1.2.0'
}
-
新建XML布局文件
在布局文件根节点设置layout_width,layout_height,layout_margin等属性控制dialog的显示大小
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="20dp"
android:background="@color/colorAccent"
android:gravity="center"
android:orientation="vertical">
<TextView
android:id="@+id/tv_1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorPrimary"
android:gravity="center"
tools:text="测试数据1" />
<ImageView
android:id="@+id/iv_1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:scaleType="centerCrop"
tools:src="@mipmap/ic_launcher" />
<Button
android:id="@+id/btn_1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="按钮1" />
</LinearLayout>
-
在代码中调用
AnyDialog.with(MainActivity.this)
.contentView(R.layout.dialog_test_1)
// .backgroundBlur(20) // 设置背景模糊度
.backgroundColorInt(0x33000000)
.touchOutsideCancelable(true)
.clickBackCancelable(true)
.bindData(new IDataBinder() {
@Override
public void bind(AnyDialog anyDialog) {
TextView tv_1 = anyDialog.getView(R.id.tv_1);
tv_1.setText("这是在bindData()方法中绑定的数据");
ImageView iv_1 = anyDialog.getView(R.id.iv_1);
iv_1.setImageResource(R.mipmap.ic_launcher);
}
})
.onClick(R.id.btn_1, new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(MainActivity.this, "点击了btn_1",Toast.LENGTH_SHORT).show();
}
})
.show();
-
注意
发现 bug 请联系 QQ302833254
网友评论
可以看到我的GitHub上面有3个功能比较类似的可以实现弹窗的框架。分别为AnyDialog、AnyLayer和FloatingLayer。可能大家有点混淆,为什么同一个功能要写3个框架?为了骗点击数?在这里向大家说明下每个框架的针对点。
首先是AnyDialog,他继承自Dialog,目的是方便Dialog的创建和使用。
再者是FloatingLayer,他是AnyLayer的一个最初版,写他的目的是因为有时候Dialog会被导航栏遮挡,或者Dialog的出现消失动画会经过黑色的导航栏区域,看着很不爽,很别扭。所以就想如果Dialog的范围能和当前的Activity的显示范围一样就好了,因此写了一个FloatingLayer,让他依附于Activity,控制一个View的动态添加和移除。
最后是AnyLayer,随着FloatingLayer的完善,我重构了代码,分离出了3个关键类,让他不再仅为实现Dialog效果,还可以实现PopupWindow和悬浮菜单等效果。因此我觉得有必要给他一个新的名字了,也是为了和AnyDialog相呼应,因此定名为AnyLayer。
所以可以看出,FloatingLayer其实是废了