Android development Tips

Source: Internet
Author: User

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!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.