NiftyNotification的效果如图所示(部分):
NiftyNotification在github上的项目主页是:https://github.com/sd6352051/NiftyNotification
NiftyNotification本身又依赖于另外一个github上的第三方开源项目NineOldAndroids,NineOldAndroids在github上的项目主页是:https://github.com/JakeWharton/NineOldAndroids
正确添加NineOldAndroids引用后,即可直接使用NiftyNotification。简单期间,甚至可以直接将NiftyNotification的单个jar包下载后加入到自己的项目libs中,然后直接使用。
(导入NineOldAndroids的library作为第一个库,添加NineOldAndroids的library作为第二个库,让第二个库引用第一个库,导入NiftyNotification-master\app\src\main作为测试工程,并引用第二个库)
NiftyNotification无需配置xml文件,只需像Android原生的Toast那样写上层Java代码即可,NiftyNotification的Java代码写法简单,可设置的参数丰富,可定制性强,摘录NiftyNotification项目中的部分Java代码示例:
<pre name="code" class="java">package com.gitonway.lee.niftynotification; import android.app.Activity; import android.os.Bundle; import android.view.Gravity; import android.view.View; import android.widget.Toast; import com.gitonway.lee.niftynotification.lib.Configuration; import com.gitonway.lee.niftynotification.lib.Effects; import com.gitonway.lee.niftynotification.lib.NiftyNotificationView; public class MainActivity extends Activity { private Effects effect; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } public void showNotify(View v){ String msg="Hi,i'm MicDull."; switch (v.getId()){ case R.id.scale:effect=Effects.scale;break; case R.id.thumbSlider:effect=Effects.thumbSlider;break; case R.id.jelly:effect=Effects.jelly;break; case R.id.slidein:effect=Effects.slideIn;break; case R.id.flip:effect=Effects.flip;break; case R.id.slideOnTop:effect=Effects.slideOnTop;break; case R.id.standard:effect=Effects.standard;break; } NiftyNotificationView.build(this,msg, effect,R.id.mLyout) .setIcon(R.drawable.a) //You must call this method if you use ThumbSlider effect .show(); // You can configure like this // The default /* Configuration cfg=new Configuration.Builder() .setAnimDuration(700) .setDispalyDuration(1500) .setBackgroundColor("#FFBDC3C7") .setTextColor("#FF444444") .setIconBackgroundColor("#FFFFFFFF") .setTextPadding(5) //dp .setViewHeight(48) //dp .setTextLines(2) //You had better use setViewHeight and setTextLines together .setTextGravity(Gravity.CENTER) //only text def Gravity.CENTER,contain icon Gravity.CENTER_VERTICAL .build(); NiftyNotificationView.build(this,msg, effect,R.id.mLyout,cfg) .setIcon(R.drawable.a) //remove this line ,only text .setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { //add your code } }) .show(); */
<span style="white-space:pre"> </span>// show(boolean) allow duplicates or showSticky() sticky notification,you can call removeSticky() method close it } }