android-5.0
1.Design Library
CardView
RecyclerView
ToolBar
FloatingActionButton
TextInputLayout
TabLayout
NavigationView
CoordinatorLayout
AppBarLayout
CollapsingToolbarLayout
NestedScrolling
Snackbar
2.動態(tài)替換Theme
MaterialTheme配色方案:www.materialpalette.com?
修改狀態(tài)欄老翘,ActionBar待逞,界面背景榴啸,NavigationBar的顏色滓彰。讓Activity使用自定義的Theme。
@color/colorWindowBackground
動態(tài)替換Theme的步驟:
定義至少2套theme
調(diào)用setTheme方法設(shè)置當(dāng)前的theme迂烁,但是該方法要在setContentView之前看尼,如:
setTheme(mTheme);
setContentView(R.layout.activity_main);
設(shè)置了Theme,需要finish當(dāng)前Activity盟步,然后重啟當(dāng)前Activity狡忙,讓Theme生效
Intent intent = getActivity().getIntent();
getActivity().finish();//結(jié)束當(dāng)前的Activity
getActivity().overridePendingTransition(0,0);//不要動畫
startActivity(intent);
3.View的高度與陰影
官網(wǎng)介紹:https://developer.android.com/intl/zh-tw/training/material/shadows-clipping.html?
View新增屬性z軸,用來體現(xiàn)Material Design中的層次址芯,影響因素2個:elevation和translationZ
View高度= elevation + translationZ
elevation表示view的高度,高度越大窜觉,陰影越大谷炸,可以在xml中直接使用屬性, 也可以在代碼中使用view.setEvelvation();
android:elevation="10dp"
transtionZ屬性表示view在Z方向移動的距離禀挫,一般用于屬性動畫中
android:translationZ="10dp"
高度影響View的繪制順序旬陡,過去是按View添加順序繪制,先添加的先繪制语婴,現(xiàn)在高度小的先繪制描孟,因為高度小的,層級低砰左,在下面匿醒, 高度相同的,按添加順序繪制
注意:
如果View的背景色為透明缠导,則不會顯示出陰影效果
只有子View的大小比父View小時廉羔,陰影才能顯示出來
4.View的輪廓與裁剪(在Android5.1以及以上才有效果)
官網(wǎng)介紹:https://developer.android.com/intl/zh-tw/training/material/shadows-clipping.html?
View增加了輪廓概念,輪廓用來表示怎么顯示陰影,也就是說輪廓什么形狀,陰影就顯示什么形狀僻造。
View的輪廓可以通過outlineProvider屬性設(shè)置憋他,默認(rèn)是依據(jù)于background的,還有其他3個取值:bounds,none,paddingBounds
android:outlineProvider="bounds"
none:即使設(shè)置了evaluation也不顯示陰影
background:按背景來顯示輪廓髓削,如果background是顏色值竹挡,則輪廓就是view的大小,如果是shape立膛,則按shape指定的形狀作為輪廓
bounds: View的矩形大小作輪廓
paddedBounds: View的矩形大小減去padding的值后的大小作輪廓揪罕。
可以通過setOutlineProvider()方法自定義輪廓:
tv_blue.setOutlineProvider(new ViewOutlineProvider() {
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
@Override
public void getOutline(View view, Outline outline) {
outline.setOval(0,0,
view.getWidth(),view.getHeight());
}
});
注意:如果background是圖片,那只能通過代碼setOutlineProvider()來指定輪廓
View的裁剪是指將View按照輪廓裁剪,能改變View的形狀耸序,如圓形頭像:
先設(shè)置輪廓:
再設(shè)置根據(jù)輪廓裁剪View,目前只支持對矩形忍些,圓形,圓角矩形的裁剪:
//設(shè)置對View進(jìn)行裁剪
tv_clip.setClipToOutline(true);
5.Palette的使用
使用Palette可以讓我們從一張圖片中拾取顏色坎怪,將拾取到的顏色賦予ActionBar罢坝,StatusBar以及背景色可以讓界面色調(diào)實現(xiàn)統(tǒng)一
使用Palette需要添加以下依賴:compile 'com.android.support:palette-v7:23.0.0+'
Palette提供的API傳入Bitmap即可獲取Palette對象,以下是同步和異步使用方式:
//同步獲取,需要在子線程中使用
Palette palette = Palette.from(drawable.getBitmap()).generate();
//異步獲取搅窿,可以在主線程中使用
Palette.from(drawable.getBitmap()).generate(new Palette.PaletteAsyncListener() {
@Override
public void onGenerated(Palette palette) {
}
});
得到Palette對象后嘁酿,獲取其中的顏色,顏色對應(yīng)如下:
vibrant? ? ? -有活力的顏色
lightVibrant -有活力的亮色
darkVibrant? -有活力的暗色
muted? ? ? ? -柔和暗淡的顏色
lightMuted? -柔和的亮色
darkMuted? ? -柔和的暗色
獲取指定顏色的采樣對象男应,獲取采樣得到的顏色:
//我們可以直接使用palette獲取指定顏色:
palette.getLightMutedColor(defaultColor);
//一般也可以先獲取采樣對象Swatch,從Swatch中獲取我們需要的顏色:
//獲取有活力顏色的采樣對象
Palette.Swatch vibrantSwatch = palette.getVibrantSwatch();
采樣對象Swatch提供了以下方法來獲取顏色:
//swatch.getPopulation(): the amount of pixels which this swatch represents.
//swatch.getRgb(): the RGB value of this color.
//swatch.getHsl(): the HSL value of this color闹司,即色相,飽和度沐飘,明度.
//swatch.getBodyTextColor(): the RGB value of a text color which can be displayed on top of this color.
//swatch.getTitleTextColor(): the RGB value of a text color which can be displayed on top of this color
//一般會將getRgb設(shè)置給控件背景色游桩,getBodyTextColor()設(shè)置給文字顏色
textView.setBackgroundColor(vibrantSwatch.getRgb());
textView.setTextColor(vibrantSwatch.getBodyTextColor());
6.水波紋動畫,自定義水波紋動畫以及狀態(tài)選擇器動畫
首先耐朴,在Android5.0以上借卧,點擊效果默認(rèn)自帶水波紋效果,并且有2種選擇:
//矩形邊框水波紋
android:background="?android:attr/selectableItemBackground"
//無邊框限制水波紋
android:background="?android:attr/selectableItemBackgroundBorderless"
自定義水波紋動畫
使用ViewAnimationUtils創(chuàng)建圓形水波紋動畫筛峭,注意該動畫不能在Activity的onCreate方法中執(zhí)行:
Animator circularReveal = ViewAnimationUtils.createCircularReveal(text, 0, text.getHeight() , 1f, text.getWidth()*2);
circularReveal.setDuration(1000);
circularReveal.start();
使用ripple標(biāo)簽或者RippleDrawable可以更改控件水波紋動畫顏色:
定義帶有屬性動畫的狀態(tài)選擇器
通過stateListAnimator屬性指定狀態(tài)選擇器的動畫:
android:stateListAnimator="@drawable/selector_anim"
狀態(tài)選擇器文件中需要加入objectAnimator標(biāo)簽:
android:duration = "@android:integer/configshortAnimTime"
android:valueTo = "0.2"
android:valueFrom = "1"
android:valueType = "floatType" >
同樣铐刘,狀態(tài)選擇器動畫可以用代碼方式加載
//加載動畫
AnimatorInflater.loadStateListAnimator();
//設(shè)置動畫
View.setStateListAnimator();
定義帶有幀動畫的狀態(tài)選擇器,需要設(shè)置給background屬性影晓,不是stateListAnimator镰吵,如下所示:
android:state_pressed = "true" />
android:drawable = "@drawable/drawableD" />
7. service的注冊必須顯示注冊,不能隱式注冊挂签,相關(guān)鏈接
http://www.eoeandroid.com/thread-568853-1-1.html?
現(xiàn)象:Service Intent must be explicit:
解決:intent.setPackage("XXXXX")疤祭;
8.android5.0art運(yùn)行報錯:
http://www.eoeandroid.com/forum.php?mod=viewthread&tid=564427?
9.webview坑
It's beceause of Cookie Policy, to fix it, you should add this :
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
super.init();
// Allow third party cookies for Android Lollipop
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
WebView webView = (WebView)super.appView;
CookieManager cookieManager = CookieManager.getInstance();
cookieManager.setAcceptThirdPartyCookies(webView,true);
}
super.loadUrl(Config.getStartUrl());
}
if you are using Android Lollipop, then
CookieManager.getInstance().setAcceptCookie(true);
won't work. You need to use
CookieManager.getInstance().setAcceptThirdPartyCookies(true);
10.notification適配
http://blog.csdn.net/sk719887916/article/details/40541143?
11.JobScheduler來執(zhí)行一些需要滿足特定條件但不緊急的后臺任務(wù),APP利用JobScheduler來執(zhí)行這些特殊的后臺任務(wù)時來減少電量的消耗饵婆。
12.AnimationDrawable在5.0及以上已優(yōu)化但盡量不要使用画株,它在初始化時就將所有圖片加載到內(nèi)存中,特別占內(nèi)存啦辐,并且不能釋放谓传,釋放后下次加載時會報錯
13.三星5.0-5.1機(jī)型上DatePicker控件會崩潰。MIUI上SYSTEM_ALERT_WINDOW需要額外申請權(quán)限芹关,默認(rèn)會拒絕掉续挟,除非type設(shè)置為TYPE_TOAST。
14.5.0以上關(guān)閉通知權(quán)限彈不出toast http://blog.csdn.net/qq_25867141/article/details/52807705?
15.FlashLight按照以前的接口是不能用了侥衬,注意是不能用了诗祸,所以一定要做版本適配跑芳,Lollipop上把Camera直接杠掉,從新弄了一套Camera2直颅,
詳情可以去看Lollipop狀態(tài)欄閃光燈開關(guān)的源碼https://android.googlesource.com/platform/frameworks/base/+/android-5.0.0_r2/packages/SystemUI/src/com/android/systemui/statusbar/policy/FlashlightController.java?
16.ActivityManger中通過getRunningTask獲取當(dāng)前列表也是禁用了博个,這個是代碼上注釋的描述
@deprecated As of {@link android.os.Build.VERSION_CODES#LOLLIPOP},
this method is no longer available to third party applications:
the introduction of document-centric recents means it can leak person information to the caller.
For backwards compatibility, it will still return a small subset of its data: at least the caller's own tasks, and possibly some other tasks such as home that are known to not be sensitive.
這就禁止后我就無法獲取到當(dāng)前運(yùn)行的packageName了,也就沒法進(jìn)行一些涉及到需求的判斷了功偿。目前我還沒找到很好的解決方案盆佣,涉及到系統(tǒng)設(shè)計的問題,可能只能從產(chǎn)品上去改進(jìn)了
17.支持Vector圖片(SVG標(biāo)準(zhǔn))
18.元素共享及兼容4.x
http://blog.csdn.net/u012342082/article/details/50599596?
19.狀態(tài)欄沉浸式
http://niorgai.github.io/2016/03/20/Android-transulcent-status-bar/?
android-6.0
1.同一個APP在api <=22的sdk情況下編譯械荷,可以運(yùn)行正常共耍,不存在閃退或者.so庫加載失敗的情況,當(dāng)你采用api >=23的sdk編譯的時候吨瞎,
安裝到Android 6.0及其以上的手機(jī)的時候痹兜,大范圍出現(xiàn)崩潰 或者.so庫加載失敗,而在6.0以下的手機(jī)卻正常颤诀。Catch的信息:dlopen failed:
cannot locate symbol "XXXX" xxxx.so字旭。
解決方案:主要有兩種:
1-委曲求全,指標(biāo)不治本崖叫,把你的APK編譯時API降低到23以下谐算,還出問題就繼續(xù)降低,這意味著归露,你很多Android Sdk的新控件用不了;
2-在Application.mk中修改APP_STL斤儿,重新編譯.so剧包,如果,我說如果你沒有源碼往果,那么悲劇了疆液,要么等他們解決,要么采用第一種陕贮,建議嘗試堕油,
APP_STL := gnustl_shared,這種方式肮之,對于所需要的外部動態(tài)鏈接函數(shù)掉缺、符號,在NDK 13b中都會獨立生成一份戈擒,全部引用就解決此類問題眶明,例如
private void load() {
try {
System.loadLibrary("gnustl_shared");
System.loadLibrary("speex");
}
catch (Throwable e) { }
}
2.運(yùn)行時權(quán)限處理
https://www.aswifter.com/2015/11/04/android-6-permission/
3.使用SYSTEM_ALERT_WINDOW繪制的懸浮窗不能含有elevation屬性,否則會在真機(jī)上崩潰筐高,模擬器正常搜囱。
android-7.0
1.DiffUtil RecyclerView幫助類
2.多窗口模式
3.ConstraintLayout增強(qiáng)RelativeLayout解決多層嵌套問題
4.適配
http://www.devio.org/2016/09/28/Android7.0%e9%80%82%e9%85%8d%e5%bf%83%e5%be%97/?
1-目錄被限制訪問 間接導(dǎo)致Notification的點擊無效的問題
私有文件的文件權(quán)限不在放權(quán)給所有的應(yīng)用丑瞧,使用MODE_WORLD_READABLE或MODE_WORLD_WRITEABLE進(jìn)行的操作將觸發(fā)SecurityException
給其他應(yīng)用傳遞file:// URI類型的Uri,可能會導(dǎo)致接受者無法訪問該路徑蜀肘。 因此绊汹,在Android7.0中嘗試傳遞file:// URI會觸發(fā)FileUriExposedException。
DownloadManager不再按文件名分享私人存儲的文件扮宠。COLUMN_LOCAL_FILENAME在Android7.0中被標(biāo)記為deprecated西乖, 舊版應(yīng)用在訪問COLUMN_LOCAL_FILENAME時可能出現(xiàn)無法訪問的路徑。
面向Android N或更高版本的應(yīng)用在嘗試訪問COLUMN_LOCAL_FILENAME時會觸發(fā)SecurityException涵卵。
2-應(yīng)用間共享文件
在Android7.0系統(tǒng)上浴栽,Android框架強(qiáng)制執(zhí)行了StrictMode API政策禁止向你的應(yīng)用外公開file:// URI。 如果一項包含文件file:// URI類型 的Intent離開你的應(yīng)用轿偎,應(yīng)用失敗典鸡,
并出現(xiàn)FileUriExposedException異常,如調(diào)用系統(tǒng)相機(jī)拍照坏晦,或裁切照片
3-使用FileProvider
5.PackageManager增加了3個abstract方法萝玷,如果繼承這個類,需要重寫下面的方法昆婿,否則在三星的有些機(jī)器上會crash
getPackageGids(String packageName, int flags)
getPackageUid(String packageName, int flags)
hasSystemFeature(String name, int version)
6.Activity的performStop增加了boolean參數(shù)球碉,需要反射調(diào)用的時候要注意區(qū)分
7.在Android 6.0及以下設(shè)置textScaleX為0是沒有問題的,在7.1的時候仓蛆,這個屬性設(shè)置為>0能正常顯示睁冬,但是到設(shè)置為0的時候就掛了。
android-8.0
1.移除HttpsURLConnection中不安全的TLS版本回退
http://developers.googleblog.cn/2017/04/android-o-httpsurlconnection-tls.html?