Alerter
7.2.4
该库旨在克服 Toast 和 Snackbar 的限制,同时降低布局的复杂性。
考虑到简单性,Alerter 采用构建器模式来促进轻松集成到任何应用程序中。可定制的警报视图会动态添加到窗口的装饰视图中,覆盖所有内容。
将 JitPack.io Maven 存储库包含在项目的 build.gradle 文件中
allprojects {
repositories {
maven { url " https://jitpack.io " }
}
}
然后将此依赖项添加到应用程序的 build.gradle 文件中
dependencies {
implementation ' com.github.tapadoo:alerter:$current-version '
}
来自活动 -
Alerter .create( this @DemoActivity)
.setTitle( " Alert Title " )
.setText( " Alert text... " )
.show()
或者来自片段 -
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()
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()
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()
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()
如果您要报告问题或考虑做出贡献,请阅读本文!
有关许可权利和限制 (MIT),请参阅 LICENSE 文件。
版权所有 2017 Tapadoo,都柏林。