Welcome to follow my GitHub and follow my csdn.
Introduce some of the small knowledge points that will be used frequently in Android development.
1. Download folder
Absolute path
/storage/emulated/0/Download/xxx
Traverse
Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS); File[]file.listFiles(); fori0ifiles.length; ++i{ Log.e(TAG, files[i].getAbsolutePath()); }
2. Butterknife Multi-parameter
Binding 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
Submodule and git can be kept in real-time sync.
Add to
add https://github.com/SpikeKing/DroidPlugin.git DroidPlugin
Use
gitsubmoduleupdate--init--recursive
Import, with more than one path, preceded by no colon (:).
include‘:app‘‘DroidPlugin:project:Libraries:DroidPlugin‘
Reference
project(‘:DroidPlugin:project:Libraries:DroidPlugin‘)
4. Update GitHub's Fork Library
Reference
5. Detect if the app is installed
Use Packagemanager.
// 检查App是否安装privatebooleanappInstalledOrNot(String uri) { PackageManager pm = getPackageManager(); boolean app_installed; try { pm.getPackageInfo(uri, PackageManager.GET_ACTIVITIES); true; catch (PackageManager.NameNotFoundException e) { false; } return app_installed;}
6. Canvas Redraw
Invalidate (). Reference.
7. Default Click effect of the button
Ripple effect (5.0+), Shadow Effect (5.0-).
android:background="?android:attr/selectableItemBackground"
Inheriting styles
<!--button--> <style name = "Personinfobutton" parent = "@android: Style/buttonbar" > <item name = "android :layout_width " >@DIMEN/D80DP</ITEM> <item name= "Android:layout_ Height " > @dimen/d32dp</item> <item name=" android:textsize " > @dimen/d14sp</item> </style
Note: @android: Style/buttonbar
8. Proguard Remove Log information
By default, LOG.I,. V, can be specified for deletion. D,. E. Reference.
# 删除Log-assumenosideeffects class android.util.Log { *; }-assumenosideeffects class android.util.Log { public static *** d(...); public static *** e(...);}
9. Simplifying the use of databases
When working with a database, the operation is somewhat complex, and the sugar Library simplifies its use. Reference.
‘com.github.satyan:sugar:1.3‘
10. Click the EditView that is populated with the link.
By adding a non-placeholder space at the end ("\u200b").
// 设置可以点击和编辑的EditText privatevoidsetEditClickable() { mEtEditText.setMovementMethod(LinkMovementMethod.getInstance()); new SpannableString("http://www.baidu.com"); Linkify.addLinks(spannable, Linkify.WEB_URLS); // 添加了零宽度空格(?\u200B???), 才可以点击到最后的位置, 否则会触发链接 "\u200B"); mEtEditText.setText(text); }
Ok. That ' s all!
Android Development Tips