zoukankan      html  css  js  c++  java
  • 生动有趣的动画Toast--第三方开源--NiftyNotification

    NiftyNotification在github上的项目主页是:https://github.com/sd6352051/NiftyNotification
    NiftyNotification本身又依赖于另外一个github上的第三方开源项目NineOldAndroids,NineOldAndroids在github上的项目主页是:https://github.com/JakeWharton/NineOldAndroids
    正确添加NineOldAndroids引用后,即可直接使用NiftyNotification。简单期间,甚至可以直接将NiftyNotification的单个jar包下载后加入到自己的项目libs中,然后直接使用。
    NiftyNotification无需配置xml文件,只需像Android原生的Toast那样写上层Java代码即可,NiftyNotification的Java代码写法简单,可设置的参数丰富,可定制性强,摘录NiftyNotification项目中的部分Java代码示例:

    activity_main.xml:

     1 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
     2     xmlns:tools="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     <TextView
    10         android:id="@+id/title"
    11         android:layout_width="match_parent"
    12         android:layout_height="48dp"
    13         android:background="#000000"
    14         android:gravity="center"
    15         android:text="Nifty Modal Notification Effects"
    16         android:textColor="#FFFFFF" />
    17 
    18     <ScrollView
    19         android:layout_width="match_parent"
    20         android:layout_height="wrap_content"
    21         android:layout_below="@+id/title"
    22         android:scrollbars="none" >
    23 
    24         <LinearLayout
    25             android:layout_width="match_parent"
    26             android:layout_height="wrap_content"
    27             android:orientation="vertical"
    28             android:padding="5dp" >
    29 
    30             <Button
    31                 android:id="@+id/scale"
    32                 style="@style/my_btn"
    33                 android:text="SCALE" />
    34 
    35             <Button
    36                 android:id="@+id/thumbSlider"
    37                 style="@style/my_btn"
    38                 android:text="THUMB SLIDER" />
    39 
    40             <Button
    41                 android:id="@+id/jelly"
    42                 style="@style/my_btn"
    43                 android:text="JELLY" />
    44 
    45             <Button
    46                 android:id="@+id/slidein"
    47                 style="@style/my_btn"
    48                 android:text="SLIDE IN" />
    49 
    50             <Button
    51                 android:id="@+id/flip"
    52                 style="@style/my_btn"
    53                 android:text="FLIP" />
    54 
    55             <Button
    56                 android:id="@+id/slideOnTop"
    57                 style="@style/my_btn"
    58                 android:text="SLIDE ON TOP" />
    59 
    60             <Button
    61                 android:id="@+id/standard"
    62                 style="@style/my_btn"
    63                 android:text="STANDARD" />
    64         </LinearLayout>
    65     </ScrollView>
    66 
    67     <RelativeLayout
    68         android:id="@+id/mLyout"
    69         android:layout_width="match_parent"
    70         android:layout_height="match_parent"
    71         android:layout_below="@+id/title"
    72         android:clipChildren="true" >
    73     </RelativeLayout>
    74 
    75 </RelativeLayout>

    MainActivity.java:

     1 package com.gitonway.lee.niftynotification;
     2 
     3 import android.app.Activity;
     4 import android.os.Bundle;
     5 import android.view.Gravity;
     6 import android.view.View;
     7 import android.widget.Toast;
     8 
     9 import com.gitonway.lee.niftynotification.lib.Configuration;
    10 import com.gitonway.lee.niftynotification.lib.Effects;
    11 import com.gitonway.lee.niftynotification.lib.NiftyNotificationView;
    12 
    13 public class MainActivity extends Activity {
    14     private Effects effect;
    15 
    16     @Override
    17     protected void onCreate(Bundle savedInstanceState) {
    18         super.onCreate(savedInstanceState);
    19         setContentView(R.layout.activity_main);
    20     }
    21 
    22     public void showNotify(View v){
    23 
    24         String msg="Today we’d like to share a couple of simple styles and effects for android notifications.";
    25 
    26         switch (v.getId()){
    27             case R.id.scale:effect=Effects.scale;break;
    28             case R.id.thumbSlider:effect=Effects.thumbSlider;break;
    29             case R.id.jelly:effect=Effects.jelly;break;
    30             case R.id.slidein:effect=Effects.slideIn;break;
    31             case R.id.flip:effect=Effects.flip;break;
    32             case R.id.slideOnTop:effect=Effects.slideOnTop;break;
    33             case R.id.standard:effect=Effects.standard;break;
    34         }
    35 
    36 
    37 
    38 
    39 //        NiftyNotificationView.build(this,msg, effect,R.id.mLyout)
    40 //                .setIcon(R.drawable.lion)         //You must call this method if you use ThumbSlider effect
    41 //                .show();
    42 
    43 
    44 
    45 //        You can configure like this
    46 //        The default
    47 
    48         Configuration cfg=new Configuration.Builder()
    49                 .setAnimDuration(700)
    50                 .setDispalyDuration(1500)
    51                 .setBackgroundColor("#FFBDC3C7")
    52                 .setTextColor("#9C27B0")
    53                 .setIconBackgroundColor("#42A5F5")
    54                 .setTextPadding(5)                      //dp
    55                 .setViewHeight(48)                      //dp
    56                 .setTextLines(2)                        //You had better use setViewHeight and setTextLines together
    57                 .setTextGravity(Gravity.CENTER)         //only text def  Gravity.CENTER,contain icon Gravity.CENTER_VERTICAL
    58                 .build();
    59 //
    60         NiftyNotificationView.build(this,msg, effect,R.id.mLyout,cfg)
    61                 .setIcon(R.drawable.lion)               //remove this line ,only text
    62                 .setOnClickListener(new View.OnClickListener() {
    63                     @Override
    64                     public void onClick(View view) {
    65                         //add your code
    66                     }
    67                 })
    68                 .show();                               //  show(boolean) allow duplicates   or showSticky() sticky notification,you can call removeSticky() method close it
    69     }
    70 
    71 }
  • 相关阅读:
    第三方接口开发规范
    项目经理、技术经理、team leader
    ibatis #和$符号的区别,传入字符串而不加引号
    WindowManager.LayoutParams详解
    AIDL 编译报can be an out parameter, so you must declare it as in, out or inout原因探究
    map里的keyset()和entryset()方法.
    android 使用代码实现 RelativeLayout布局
    Android中的Selector
    intentfilter 之 data 「scheme, host, port, mimeType, path, pathPrefix, pathPattern」
    找信息的方法
  • 原文地址:https://www.cnblogs.com/zzw1994/p/5013093.html
Copyright © 2011-2022 走看看