Android Development Tips

Source: Internet
Author: User

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

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.