歡迎Follow我的GitHub, 關(guān)注我的簡(jiǎn)書(shū). 其余參考Android目錄.

本文的合集已經(jīng)編著成書(shū),高級(jí)Android開(kāi)發(fā)強(qiáng)化實(shí)戰(zhàn),歡迎各位讀友的建議和指導(dǎo)。在京東即可購(gòu)買(mǎi):https://item.jd.com/12385680.html

我會(huì)介紹關(guān)于Android的一些有趣的小知識(shí)點(diǎn). 本文是第三篇, 其余第一篇, 第二篇.
1. UIAutomatorViewer
自動(dòng)化測(cè)試是Android測(cè)試的趨勢(shì), 穩(wěn)定\復(fù)用, 最常用的工具就是Espresso.
使用UIAutomatorViewer獲取資源的Id,
位置/android-sdk/tools/uiautomatorviewer, 點(diǎn)擊即可使用.

2. GitHub標(biāo)簽
網(wǎng)址, 比如:
[圖片上傳失敗...(image-ca4295-1530169346314)]
[圖片上傳失敗...(image-874431-1530169346315)]
3. 有趣的修改SVG庫(kù)
地址, 加載SVG格式的圖片, 修改顏色屬性.

4. 請(qǐng)求和生成的Json插件
JSONOnlineViewer, 網(wǎng)絡(luò)請(qǐng)求插件, 獲取Json數(shù)據(jù), 位置View->JSONViewer.
GsonFormat, 根據(jù)Json自動(dòng)生成類(lèi)的插件, 在Command+N里面.
附一張插件的截圖, 其他隨意.

5. Retrofit2+Okhttp3的Interceptor設(shè)置方式
Retrofit升級(jí)到beta3版本, 使用了最新Okhttp3, Interceptor的設(shè)置方式發(fā)生改變.
舊版
OkHttpClient client = new OkHttpClient().Builder();
HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor();
loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BASIC);
MarvelSigningInterceptor signingInterceptor = new MarvelSigningInterceptor(
BuildConfig.MARVEL_PUBLIC_KEY, BuildConfig.MARVEL_PRIVATE_KEY);
client.interceptors().add(signingInterceptor);
client.interceptors().add(loggingInterceptor);
替換, 新版
HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor();
loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BASIC);
MarvelSigningInterceptor signingInterceptor = new MarvelSigningInterceptor(
BuildConfig.MARVEL_PUBLIC_KEY, BuildConfig.MARVEL_PRIVATE_KEY);
OkHttpClient client = new OkHttpClient.Builder()
.addInterceptor(signingInterceptor)
.addInterceptor(loggingInterceptor)
.build();
否則可能會(huì)發(fā)生: HTTP 409 Conflict, 未輸入正確的驗(yàn)證方式, 私鑰錯(cuò)誤.
6. okhttp-logging-interceptor輸出log信息
參考, 可以輸出log信息, 使用, 當(dāng)前版本是3.0.1.
compile "com.squareup.okhttp3:logging-interceptor:${libs.okhttp}"
輸出參考:
D/OkHttp: <-- 200 OK http://gateway.marvel.com/v1/public/characters?offset=0&... (1552ms, unknown-length body)
7. 透明statusbar和全屏ImageView
status bar設(shè)置成為透明顏色.
<style name="AppTheme.NoStatusBar">
<item name="android:windowTranslucentStatus">true</item>
</style>
頁(yè)面的根布局是CollapsingToolbarLayout.
<android.support.design.widget.CollapsingToolbarLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:contentDescription="@null"
android:fitsSystemWindows="true"
android:scaleType="centerCrop"
android:src="@drawable/christmas"/>
</android.support.design.widget.CollapsingToolbarLayout>
效果

其他布局無(wú)法覆蓋效果, 參考.
8. Android Studio模板
位置: File->Other Settings->Default Settings->Editor->Live Templates
熟練之后, 根據(jù)簡(jiǎn)寫(xiě)+Tab就可以使用了, 當(dāng)然也可以自己添加.

自定義模板:
縮寫(xiě)(Abbreviation), 描述(Description), 內(nèi)容(Template text), 應(yīng)用場(chǎng)景, 格式化.

9. 推薦動(dòng)畫(huà)效果的網(wǎng)站
網(wǎng)址, 網(wǎng)站里面有很多好玩的動(dòng)畫(huà)效果, 而且都是編程實(shí)現(xiàn), 方便移植, 如雪花效果.
10. ListView的ViewHolder
Android官方推薦使用RecyclerView代替ListView, 但是很多守舊的人不想這么做, 那么, 也需要使用ViewHolder提升加載速度. 參考.
基本用法.
static class ViewHolder() {
TextView testName;
TextView testDesc;
}
...
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View rowView = convertView;
// 初始化ViewHolder
if (convertView == null) {
LayoutInflater inflater = (LayoutInflater) parent.getContext()
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
rowView = inflater.inflate(R.layout.view_test_row, parent, false);
ViewHolder viewHolder = new ViewHolder();
viewHolder.testName = (TextView) rowView.findViewById(R.id.test_tv_name);
viewHolder.testDesc = (TextView) rowView.findViewById(R.id.test_tv_desc);
rowView.setTag(viewHolder);
}
// 使用ViewHolder
ViewHolder holder = (ViewHolder) rowView.getTag();
holder.testName.setText("Test: " + position);
holder.testDesc.setText("This is number " + position + ". ");
return rowView;
}
OK, that's all! Enjoy it.