1. Download文件夾
絕對路徑
/storage/emulated/0/Download/xxx
遍歷
File file = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS);
File[] files = file.listFiles();
for (int i = 0; i < files.length; ++i) {
Log.e(TAG, files[i].getAbsolutePath());
}
2. ButterKnife多參數
綁定多個參數
@OnClick({
R.id.dialog_dau_share_wx,
R.id.dialog_dau_share_wx_timeline,
R.id.dialog_dau_share_weibo,
R.id.dialog_dau_share_qq
})
3. submodule的使用方法
submodule與git可以保持實時同步.
添加
git submodule add https://github.com/SpikeKing/DroidPlugin.git DroidPlugin
使用
git submodule update--init --recursive
導入, 路徑多於一個, 前面不添加冒號(:).
include':app', 'DroidPlugin:project:Libraries:DroidPlugin'
引用
compile project(':DroidPlugin:project:Libraries:DroidPlugin')
4. 更新Github的Fork庫
5. 檢測App是否安裝
使用PackageManager.
// 檢查App是否安裝privatebooleanappInstalledOrNot(String uri){
PackageManager pm = getPackageManager();
boolean app_installed;
try {
pm.getPackageInfo(uri, PackageManager.GET_ACTIVITIES);
app_installed = true;
} catch (PackageManager.NameNotFoundException e) {
app_installed = false;
}
return app_installed;
}
6. Canvas重繪
7. 按鈕的默認點擊效果
波紋效果(5.0+), 陰影效果(5.0-).
android:background="?android:attr/selectableItemBackground"
繼承樣式
<!--按鈕--><stylename="PersonInfoButton"parent="@android:style/ButtonBar">
<itemname="android:layout_width">@dimen/d80dp</item>
<item name="android:layout_height">@dimen/d32dp</item>
<item name="android:textSize">@dimen/d14sp</item>
</style>
注意: @android:style/ButtonBar
8. Proguard去除Log信息
默認刪除log.i, .v, 可以指定刪除.d, .e. 參考.
# 刪除Log
-assumenosideeffects classandroid.util.Log{ *; }
-assumenosideeffects classandroid.util.Log{
publicstatic *** d(...);
publicstatic *** e(...);
}
9. 簡化數據庫的使用
在使用數據庫時, 操作有些複雜, Sugar庫簡化使用方法. 參考.
compile 'com.github.satyan:sugar:1.3'
10. 點擊被填充鏈接的EditView.
通過在結尾處添加一個不佔位的空格("\u200B").
// 設置可以點擊和編輯的EditTextprivatevoidsetEditClickable() {
mEtEditText.setMovementMethod(LinkMovementMethod.getInstance());
Spannable spannable = new SpannableString("http://www.baidu.com");
Linkify.addLinks(spannable, Linkify.WEB_URLS);
// 添加了零寬度空格(\u200B), 纔可以點擊到最後的位置, 否則會觸發鏈接
CharSequence text = TextUtils.concat(spannable, "\u200B");
mEtEditText.setText(text);
}
SimpleDateFormat dateFm = new SimpleDateFormat("MM/dd/yyyy hh:mm:ss a",
Locale.ENGLISH);
1.出現錯誤有可能是因爲Locale問題,比如用你的代碼輸出當前時間,後面得到了“午後”兩個漢字。(我是中文系統)
2.HH 是 0-23 h 是0-12
這樣就沒有問題了。