你的位置:首页 > 操作系统

[操作系统]Android动画效果生动有趣的通知NiftyNotification(Android Toast替代品)


NiftyNotification在github上的项目主页是:https://github.com/sd6352051/NiftyNotification
NiftyNotification本身又依赖于另外一个github上的第三方开源项目NineOldAndroids,NineOldAndroids在github上的项目主页是:https://github.com/JakeWharton/NineOldAndroids
正确添加NineOldAndroids引用后,即可直接使用NiftyNotification。简单期间,甚至可以直接将NiftyNotification的单个jar包下载后加入到自己的项目libs中,然后直接使用。
NiftyNotification无需配置

 1 package com.gitonway.lee.niftynotification; 2  3 import android.app.Activity; 4 import android.os.Bundle; 5 import android.view.View; 6 import com.gitonway.lee.niftynotification.lib.Effects; 7 import com.gitonway.lee.niftynotification.lib.NiftyNotificationView; 8  9 public class MainActivity extends Activity {10   private Effects effect;11 12   @Override13   protected void onCreate(Bundle savedInstanceState) {14     super.onCreate(savedInstanceState);15     setContentView(R.layout.activity_main);16   }17 18   public void showNotify(View v) {19 20     String msg = "今天天气不错,心情也很好啊 !";21 22     switch (v.getId()) {23     case R.id.scale:24       effect = Effects.scale;25       break;26     case R.id.thumbSlider:27       effect = Effects.thumbSlider;28       break;29     case R.id.jelly:30       effect = Effects.jelly;31       break;32     case R.id.slidein:33       effect = Effects.slideIn;34       break;35     case R.id.flip:36       effect = Effects.flip;37       break;38     case R.id.slideOnTop:39       effect = Effects.slideOnTop;40       break;41     case R.id.standard:42       effect = Effects.standard;43       break;44     }45 46     NiftyNotificationView.build(this, msg, effect, R.id.mLyout).setIcon(R.drawable.lion) // You47                                                 // must48                                                 // call49                                                 // this50                                                 // method51                                                 // if52                                                 // you53                                                 // use54                                                 // ThumbSlider55                                                 // effect56         .show();57 58     // You can configure like this59     // The default60 61     // Configuration cfg=new Configuration.Builder()62     // .setAnimDuration(700)63     // .setDispalyDuration(1500)64     // .setBackgroundColor("#FFBDC3C7")65     // .setTextColor("#FF444444")66     // .setIconBackgroundColor("#FFFFFFFF")67     // .setTextPadding(5) //dp68     // .setViewHeight(48) //dp69     // .setTextLines(2) //You had better use setViewHeight and setTextLines70     // together71     // .setTextGravity(Gravity.CENTER) //only text def72     // Gravity.CENTER,contain icon Gravity.CENTER_VERTICAL73     // .build();74     //75     // NiftyNotificationView.build(this,msg, effect,R.id.mLyout,cfg)76     // .setIcon(R.drawable.lion) //remove this line ,only text77     // .setOnClickListener(new View.OnClickListener() {78     // @Override79     // public void onClick(View view) {80     // //add your code81     // }82     // })83     // .show(); // show(boolean) allow duplicates or showSticky() sticky84     // notification,you can call removeSticky() method close it85   }86 87 }

 1 <RelativeLayout ="http://schemas.android.com/apk/res/android" 2   ="http://schemas.android.com/tools" 3   android:layout_width="match_parent" 4   android:layout_height="match_parent" 5   android:background="#34495E" 6   android:orientation="vertical" 7   tools:context=".MainActivity"> 8  9   <TextView10     android:id="@+id/title"11     android:layout_width="match_parent"12     android:layout_height="48dp"13     android:background="#000000"14     android:textColor="#FFFFFF"15     android:gravity="center"16     android:text="Nifty Modal Notification Effects" />17   <ScrollView18     android:layout_width="match_parent"19     android:layout_height="wrap_content"20     android:layout_below="@+id/title"21     android:scrollbars="none">22     <LinearLayout23       android:layout_width="match_parent"24       android:layout_height="wrap_content"25       android:orientation="vertical"26       android:padding="5dp">27 28       <Button29         android:id="@+id/scale"30         style="@style/my_btn"31         android:text="SCALE"32         />33       <Button34         android:id="@+id/thumbSlider"35         style="@style/my_btn"36         android:text="THUMB SLIDER"37         />38       <Button39         android:id="@+id/jelly"40         style="@style/my_btn"41         android:text="JELLY"42         />43       <Button44         android:id="@+id/slidein"45         style="@style/my_btn"46         android:text="SLIDE IN"47         />48       <Button49         android:id="@+id/flip"50         style="@style/my_btn"51         android:text="FLIP"52         />53       <Button54         android:id="@+id/slideOnTop"55         style="@style/my_btn"56         android:text="SLIDE ON TOP"57         />58       <Button59         android:id="@+id/standard"60         style="@style/my_btn"61         android:text="STANDARD"62         />63     </LinearLayout>64   </ScrollView>65   <RelativeLayout66     android:id="@+id/mLyout"67     android:layout_below="@+id/title"68     android:layout_width="match_parent"69     android:layout_height="match_parent"70     android:clipChildren="true"71     >72 73   </RelativeLayout>74 </RelativeLayout>

运行效果图: