android-5.0
1.Design Library
CardView
RecyclerView
ToolBar
FloatingActionButton
TextInputLayout
TabLayout
NavigationView
CoordinatorLayout
AppBarLayout
CollapsingToolbarLayout
NestedScrolling
Snackbar
2.動(dòng)態(tài)替換Theme
MaterialTheme配色方案:www.materialpalette.com?
修改狀態(tài)欄,ActionBar,界面背景,NavigationBar的顏色。讓Activity使用自定義的Theme。
@color/colorWindowBackground
動(dòng)態(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);//不要?jiǎng)赢?/p>
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個(gè):elevation和translationZ
View高度= elevation + translationZ
elevation表示view的高度,高度越大,陰影越大,可以在xml中直接使用屬性, 也可以在代碼中使用view.setEvelvation();
android:elevation="10dp"
transtionZ屬性表示view在Z方向移動(dòng)的距離,一般用于屬性動(dòng)畫中
android:translationZ="10dp"
高度影響View的繪制順序,過去是按View添加順序繪制,先添加的先繪制,現(xiàn)在高度小的先繪制,因?yàn)楦叨刃〉?,層?jí)低,在下面, 高度相同的,按添加順序繪制
注意:
如果View的背景色為透明,則不會(huì)顯示出陰影效果
只有子View的大小比父View小時(shí),陰影才能顯示出來
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個(gè)取值: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,目前只支持對(duì)矩形,圓形,圓角矩形的裁剪:
//設(shè)置對(duì)View進(jìn)行裁剪
tv_clip.setClipToOutline(true);
5.Palette的使用
使用Palette可以讓我們從一張圖片中拾取顏色,將拾取到的顏色賦予ActionBar,StatusBar以及背景色可以讓界面色調(diào)實(shí)現(xiàn)統(tǒng)一
使用Palette需要添加以下依賴:compile 'com.android.support:palette-v7:23.0.0+'
Palette提供的API傳入Bitmap即可獲取Palette對(duì)象,以下是同步和異步使用方式:
//同步獲取,需要在子線程中使用
Palette palette = Palette.from(drawable.getBitmap()).generate();
//異步獲取,可以在主線程中使用
Palette.from(drawable.getBitmap()).generate(new Palette.PaletteAsyncListener() {
@Override
public void onGenerated(Palette palette) {
}
});
得到Palette對(duì)象后,獲取其中的顏色,顏色對(duì)應(yīng)如下:
vibrant? ? ? -有活力的顏色
lightVibrant -有活力的亮色
darkVibrant? -有活力的暗色
muted? ? ? ? -柔和暗淡的顏色
lightMuted? -柔和的亮色
darkMuted? ? -柔和的暗色
獲取指定顏色的采樣對(duì)象,獲取采樣得到的顏色:
//我們可以直接使用palette獲取指定顏色:
palette.getLightMutedColor(defaultColor);
//一般也可以先獲取采樣對(duì)象Swatch,從Swatch中獲取我們需要的顏色:
//獲取有活力顏色的采樣對(duì)象
Palette.Swatch vibrantSwatch = palette.getVibrantSwatch();
采樣對(duì)象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
//一般會(huì)將getRgb設(shè)置給控件背景色,getBodyTextColor()設(shè)置給文字顏色
textView.setBackgroundColor(vibrantSwatch.getRgb());
textView.setTextColor(vibrantSwatch.getBodyTextColor());
6.水波紋動(dòng)畫,自定義水波紋動(dòng)畫以及狀態(tài)選擇器動(dòng)畫
首先,在Android5.0以上,點(diǎn)擊效果默認(rèn)自帶水波紋效果,并且有2種選擇:
//矩形邊框水波紋
android:background="?android:attr/selectableItemBackground"
//無邊框限制水波紋
android:background="?android:attr/selectableItemBackgroundBorderless"
自定義水波紋動(dòng)畫
使用ViewAnimationUtils創(chuàng)建圓形水波紋動(dòng)畫,注意該動(dò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可以更改控件水波紋動(dòng)畫顏色:
定義帶有屬性動(dòng)畫的狀態(tài)選擇器
通過stateListAnimator屬性指定狀態(tài)選擇器的動(dòng)畫:
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)選擇器動(dòng)畫可以用代碼方式加載
//加載動(dòng)畫
AnimatorInflater.loadStateListAnimator();
//設(shè)置動(dòng)畫
View.setStateListAnimator();
定義帶有幀動(dòng)畫的狀態(tài)選擇器,需要設(shè)置給background屬性,不是stateListAnimator,如下所示:
android:state_pressed = "true" />
android:drawable = "@drawable/drawableD" />
7. service的注冊(cè)必須顯示注冊(cè),不能隱式注冊(cè),相關(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)行報(bào)錯(cuò):
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í)行一些需要滿足特定條件但不緊急的后臺(tái)任務(wù),APP利用JobScheduler來執(zhí)行這些特殊的后臺(tái)任務(wù)時(shí)來減少電量的消耗。
12.AnimationDrawable在5.0及以上已優(yōu)化但盡量不要使用,它在初始化時(shí)就將所有圖片加載到內(nèi)存中,特別占內(nèi)存,并且不能釋放,釋放后下次加載時(shí)會(huì)報(bào)錯(cuò)
13.三星5.0-5.1機(jī)型上DatePicker控件會(huì)崩潰。MIUI上SYSTEM_ALERT_WINDOW需要額外申請(qǐng)權(quán)限,默認(rèn)會(huì)拒絕掉,除非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)前列表也是禁用了,這個(gè)是代碼上注釋的描述
@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è)計(jì)的問題,可能只能從產(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.同一個(gè)APP在api <=22的sdk情況下編譯,可以運(yùn)行正常,不存在閃退或者.so庫加載失敗的情況,當(dāng)你采用api >=23的sdk編譯的時(shí)候,
安裝到Android 6.0及其以上的手機(jī)的時(shí)候,大范圍出現(xiàn)崩潰 或者.so庫加載失敗,而在6.0以下的手機(jī)卻正常。Catch的信息:dlopen failed:
cannot locate symbol "XXXX" xxxx.so。
解決方案:主要有兩種:
1-委曲求全,指標(biāo)不治本,把你的APK編譯時(shí)API降低到23以下,還出問題就繼續(xù)降低,這意味著,你很多Android Sdk的新控件用不了;
2-在Application.mk中修改APP_STL,重新編譯.so,如果,我說如果你沒有源碼,那么悲劇了,要么等他們解決,要么采用第一種,建議嘗試,
APP_STL := gnustl_shared,這種方式,對(duì)于所需要的外部動(dòng)態(tài)鏈接函數(shù)、符號(hào),在NDK 13b中都會(huì)獨(dú)立生成一份,全部引用就解決此類問題,例如
private void load() {
try {
System.loadLibrary("gnustl_shared");
System.loadLibrary("speex");
}
catch (Throwable e) { }
}
2.運(yùn)行時(shí)權(quán)限處理
https://www.aswifter.com/2015/11/04/android-6-permission/
3.使用SYSTEM_ALERT_WINDOW繪制的懸浮窗不能含有elevation屬性,否則會(huì)在真機(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的點(diǎn)擊無效的問題
私有文件的文件權(quán)限不在放權(quán)給所有的應(yīng)用,使用MODE_WORLD_READABLE或MODE_WORLD_WRITEABLE進(jìn)行的操作將觸發(fā)SecurityException
給其他應(yīng)用傳遞file:// URI類型的Uri,可能會(huì)導(dǎo)致接受者無法訪問該路徑。 因此,在Android7.0中嘗試傳遞file:// URI會(huì)觸發(fā)FileUriExposedException。
DownloadManager不再按文件名分享私人存儲(chǔ)的文件。COLUMN_LOCAL_FILENAME在Android7.0中被標(biāo)記為deprecated, 舊版應(yīng)用在訪問COLUMN_LOCAL_FILENAME時(shí)可能出現(xiàn)無法訪問的路徑。
面向Android N或更高版本的應(yīng)用在嘗試訪問COLUMN_LOCAL_FILENAME時(shí)會(huì)觸發(fā)SecurityException。
2-應(yīng)用間共享文件
在Android7.0系統(tǒng)上,Android框架強(qiáng)制執(zhí)行了StrictMode API政策禁止向你的應(yīng)用外公開file:// URI。 如果一項(xiàng)包含文件file:// URI類型 的Intent離開你的應(yīng)用,應(yīng)用失敗,
并出現(xiàn)FileUriExposedException異常,如調(diào)用系統(tǒng)相機(jī)拍照,或裁切照片
3-使用FileProvider
5.PackageManager增加了3個(gè)abstract方法,如果繼承這個(gè)類,需要重寫下面的方法,否則在三星的有些機(jī)器上會(huì)crash
getPackageGids(String packageName, int flags)
getPackageUid(String packageName, int flags)
hasSystemFeature(String name, int version)
6.Activity的performStop增加了boolean參數(shù),需要反射調(diào)用的時(shí)候要注意區(qū)分
7.在Android 6.0及以下設(shè)置textScaleX為0是沒有問題的,在7.1的時(shí)候,這個(gè)屬性設(shè)置為>0能正常顯示,但是到設(shè)置為0的時(shí)候就掛了。
android-8.0
1.移除HttpsURLConnection中不安全的TLS版本回退
http://developers.googleblog.cn/2017/04/android-o-httpsurlconnection-tls.html?