編輯:關於android開發
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代碼即可
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 @Override 13 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) // You 47 // must 48 // call 49 // this 50 // method 51 // if 52 // you 53 // use 54 // ThumbSlider 55 // effect 56 .show(); 57 58 // You can configure like this 59 // The default 60 61 // Configuration cfg=new Configuration.Builder() 62 // .setAnimDuration(700) 63 // .setDispalyDuration(1500) 64 // .setBackgroundColor("#FFBDC3C7") 65 // .setTextColor("#FF444444") 66 // .setIconBackgroundColor("#FFFFFFFF") 67 // .setTextPadding(5) //dp 68 // .setViewHeight(48) //dp 69 // .setTextLines(2) //You had better use setViewHeight and setTextLines 70 // together 71 // .setTextGravity(Gravity.CENTER) //only text def 72 // Gravity.CENTER,contain icon Gravity.CENTER_VERTICAL 73 // .build(); 74 // 75 // NiftyNotificationView.build(this,msg, effect,R.id.mLyout,cfg) 76 // .setIcon(R.drawable.lion) //remove this line ,only text 77 // .setOnClickListener(new View.OnClickListener() { 78 // @Override 79 // public void onClick(View view) { 80 // //add your code 81 // } 82 // }) 83 // .show(); // show(boolean) allow duplicates or showSticky() sticky 84 // notification,you can call removeSticky() method close it 85 } 86 87 }
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:textColor="#FFFFFF" 15 android:gravity="center" 16 android:text="Nifty Modal Notification Effects" /> 17 <ScrollView 18 android:layout_width="match_parent" 19 android:layout_height="wrap_content" 20 android:layout_below="@+id/title" 21 android:scrollbars="none"> 22 <LinearLayout 23 android:layout_width="match_parent" 24 android:layout_height="wrap_content" 25 android:orientation="vertical" 26 android:padding="5dp"> 27 28 <Button 29 android:id="@+id/scale" 30 31 android:text="SCALE" 32 /> 33 <Button 34 android:id="@+id/thumbSlider" 35 36 android:text="THUMB SLIDER" 37 /> 38 <Button 39 android:id="@+id/jelly" 40 41 android:text="JELLY" 42 /> 43 <Button 44 android:id="@+id/slidein" 45 46 android:text="SLIDE IN" 47 /> 48 <Button 49 android:id="@+id/flip" 50 51 android:text="FLIP" 52 /> 53 <Button 54 android:id="@+id/slideOnTop" 55 56 android:text="SLIDE ON TOP" 57 /> 58 <Button 59 android:id="@+id/standard" 60 61 android:text="STANDARD" 62 /> 63 </LinearLayout> 64 </ScrollView> 65 <RelativeLayout 66 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>
運行效果圖:
dagger2記錄篇,dagger2記錄作為一個碼農,什麼都不用多講,貼代碼 build project build module Application pub
TabLayout + ViewPager,tablayoutviewpager一、實現思路 1、在build.gradle中添加依賴,例如: compile com.
Android自動化構建之Ant多渠道打包實踐分析(下) 前言 上一篇(Android自動化構建之Ant多渠道打包實踐分析(上))已經介紹了Android的apk是如何構
AndroidStudio 1.4升級到1.5後,peer not authenticated錯誤 解決方法: 找到項目最外層的build.gradle文件,將其中的