Android development Tips
Some tips that are frequently used in Android development.
1. Download folder
Absolute path
/storage/emulated/0/Download/xxx
Traversal
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 multiple parameters
Bind multiple parameters
@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. How to Use submodule
The submodule and git can be synchronized in real time.
Add
git submodule add https://github.com/SpikeKing/DroidPlugin.git DroidPlugin
Use
git submodule update --init --recursive
Import, with more than one path. No colon (:) is added before (:).
include ':app', 'DroidPlugin:project:Libraries:DroidPlugin'
Reference
compile project(':DroidPlugin:project:Libraries:DroidPlugin')
4. Update the Fork library of Github.
Reference
5. Check whether the App is installed
Use PackageManager.
// Check whether the App has installed private boolean appInstalledOrNot (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 re-painting
Invalidate (). Reference.
7. default button clicking Effect
Ripple Effect (5.0 +), shadow effect (5.0 -).
android:background="?android:attr/selectableItemBackground"
Inherited Style
Note: @ android: style/ButtonBar
8. Proguard removes Log information
Log. I,. v is deleted by default. You can specify to delete. d,. e. reference.
# Delete Log-assumenosideeffects class android. util. log {*;}-assumenosideeffects class android. util. log {public static *** d (...); public static *** e (...);}
9. Simplify database usage
When using the database, the operation is somewhat complicated. The Sugar database is simplified for reference.
compile 'com.github.satyan:sugar:1.3'
10. Click the EditView of the filled link.
Add a space ("\ u200B") at the end ").
// Set the EditText private void setEditClickable () {mEtEditText. setMovementMethod (LinkMovementMethod. getInstance (); Spannable spannable = new SpannableString ("http://www.baidu.com"); Linkify. addLinks (spannable, Linkify. WEB_URLS); // added a zero-width space (? \ U200B ???), To the final position. Otherwise, the link CharSequence text = TextUtils. concat (spannable, "\ u200B"); mEtEditText. setText (text);} will be triggered );}
OK. That's all!