注册

罕见!!上弹窗:Alerter

alerter克服了toast和snackbar的缺点,并布局很简单


生成

为了简单起见,Alerter采用了builder模式,以便于轻松集成到任何应用程序中。


可自定义的警报视图将动态添加到窗口的装饰视图中,覆盖所有内容。


安装配置

allprojects {
repositories {
jcenter()
maven { url "https://jitpack.io" }
}
}

build.gradle


dependencies {
implementation 'com.github.tapadoo:alerter:$current-version'
}

使用


Activity -


Alerter.create(this@DemoActivity)
.setTitle("Alert Title")
.setText("Alert text...")
.show()

Fragment -


Alerter.create(activity)
.setTitle("Alert Title")
.setText("Alert text...")
.show()

展示 -


Alerter.isShowing()

隐藏 -


Alerter.hide()

定制

背景颜色

Alerter.create(this@DemoActivity)
.setTitle("Alert Title")
.setText("Alert text...")
.setBackgroundColorRes(R.color.colorAccent) // or setBackgroundColorInt(Color.CYAN)
.show()


图标

Alerter.create(this@DemoActivity)
.setText("Alert text...")
.setIcon(R.drawable.alerter_ic_mail_outline)
.setIconColorFilter(0) // Optional - Removes white tint
.setIconSize(R.dimen.custom_icon_size) // Optional - default is 38dp
.show()


自定义屏幕持续时间(毫秒)

Alerter.create(this@DemoActivity)
.setTitle("Alert Title")
.setText("Alert text...")
.setDuration(10000)
.show()

无标题

Alerter.create(this@DemoActivity)
.setText("Alert text...")
.show()


添加 Click Listener

 Alerter.create(this@DemoActivity)
.setTitle("Alert Title")
.setText("Alert text...")
.setDuration(10000)
.setOnClickListener(View.OnClickListener {
Toast.makeText(this@DemoActivity, "OnClick Called", Toast.LENGTH_LONG).show();
})
.show()


长的文本

 Alerter.create(this@DemoActivity)
.setTitle("Alert Title")
.setText("The alert scales to accommodate larger bodies of text. " +
"The alert scales to accommodate larger bodies of text. " +
"The alert scales to accommodate larger bodies of text.")
.show()


自定义进入/退出动画

  Alerter.create(this@KotlinDemoActivity)
.setTitle("Alert Title")
.setText("Alert text...")
.setEnterAnimation(R.anim.alerter_slide_in_from_left)
.setExitAnimation(R.anim.alerter_slide_out_to_right)
.show()

可见性回调

 Alerter.create(this@KotlinDemoActivity)
.setTitle("Alert Title")
.setText("Alert text...")
.setDuration(10000)
.setOnShowListener(OnShowAlertListener {
Toast.makeText(this@KotlinDemoActivity, "Show Alert", Toast.LENGTH_LONG).show()
})
.setOnHideListener(OnHideAlertListener {
Toast.makeText(this@KotlinDemoActivity, "Hide Alert", Toast.LENGTH_LONG).show()
})
.show()

自定义字体和文本外观

 Alerter.create(this@DemoActivity)
.setTitle("Alert Title")
.setTitleAppearance(R.style.AlertTextAppearance_Title)
.setTitleTypeface(Typeface.createFromAsset(getAssets(), "Pacifico-Regular.ttf"))
.setText("Alert text...")
.setTextAppearance(R.style.AlertTextAppearance_Text)
.setTextTypeface(Typeface.createFromAsset(getAssets(), "ScopeOne-Regular.ttf"))
.show()


退出

 Alerter.create(this@DemoActivity)
.setTitle("Alert Title")
.setText("Alert text...")
.enableSwipeToDismiss()
.show()


Progress Bar

 Alerter.create(this@DemoActivity)
.setTitle("Alert Title")
.setText("Alert text...")
.enableProgress(true)
.setProgressColorRes(R.color.colorAccent)
.show()


带按钮

 Alerter.create(this@KotlinDemoActivity)
.setTitle(R.string.title_activity_example)
.setText("Alert text...")
.addButton("Okay", R.style.AlertButton, View.OnClickListener {
Toast.makeText(this@KotlinDemoActivity, "Okay Clicked", Toast.LENGTH_LONG).show()
})
.addButton("No", R.style.AlertButton, View.OnClickListener {
Toast.makeText(this@KotlinDemoActivity, "No Clicked", Toast.LENGTH_LONG).show()
})
.show()


自定义layout

 Alerter.create(this@KotlinDemoActivity, R.layout.custom_layout)
.setBackgroundColorRes(R.color.colorAccent)
.also { alerter ->
val tvCustomView = alerter.getLayoutContainer()?.tvCustomLayout
tvCustomView?.setText(R.string.with_custom_layout)
}
.show()


github地址:https://github.com/Tapadoo/Alerter
下载地址:master.zip


0 个评论

要回复文章请先登录注册