Android開發中遇到的一些好用的小技巧,記錄下來方便使用。
TextUtils.isEmpty()用於檢測是否爲空
TextView.setError() 在驗證用戶輸入錯誤時顯示
Context.getCacheDir() 獲取緩存,保存在data/應用程序包名/cache/ 下,在應用程序卸載的時候,這裏會被清空
DateUtils.formatDateTime() 用來進行區域格式化工作
Formatter.formatFileSize() 把大小轉換爲MB,G,KB之類的字符串。
Linkify.addLinks() 在Text上添加鏈接
Activity.onBackPressed() 管理back鍵的方法
ActivityManager.getMemoryClass() 獲取機器還有多少內存