Android开发中这些小技巧你都知道吗?(一)
来源:互联网 发布:c语言编程用什么软件 编辑:程序博客网 时间:2024/06/10 19:34
public void startActivities (Intent[] intents)
- 该方法和我们平常用到的startActivity非常相似,只不过将Intent[]中的Intent所指向的跳转目标Activity从后往前依次添加到返回栈中。跳转完后如果按Back键的话会发现返回的顺序和Intent[]中的顺序前后一致。
Same as startActivities(Intent[], Bundle)
with no options specified.
Parameters
Throws
public static boolean isEmpty (CharSequence str)
- 我经常在项目中使用,判断字符创是否为空或是否为null非常方便。
Returns true if the string is null or 0-length.
Parameters
Returns
- true if str is null or zero length
public static Spanned fromHtml (String source)
- 一个很方便格式化Html代码的方法,但因为处理速度不太快,所以我不太经常用它。不建议用该方法处理String样式,通常建议使用Spannable来处理。
Returns displayable styled text from the provided HTML string. Any <img> tags in the HTML will display as a generic replacement image which your program can then Go through and replace with real images.
This uses TagSoup to handle real HTML, including all of the brokenness found in the wild.
public void setError (CharSequence error)
- 在TextView上不太常用,更多用在EditText上(EditText继承自TextView)提示用户输入非法。还有个多态方法setError(CharSequence error,Drawable icon)来让开发者自定义错误提示图片。
Sets the right-hand compound drawable of the TextView to the "error" icon and sets an error message that will be displayed in a popup when the TextView has focus. The icon and error message will be reset to null when any key events cause changes to the TextView's text. If the error
is null
, the error message and icon will be cleared.
public static String getStackTraceString (Throwable tr)
- 有时候我们希望程序抛出异常时能把异常信息保存到制定目录的文件中,getStackTraceString就可以将异常信息转换成字符串的形式。
Handy function to get a loggable stack trace from a Throwable
Parameters
public static LayoutInflater from (Context context)
- 和冗长的getSystemService()说Goodbye。
Obtains the LayoutInflater from the given context.
public abstract File getCacheDir ()
- 获取应用默认缓存路径“/data/data/应用包名/cache”
Returns the absolute path to the application specific cache directory on the filesystem. These files will be ones that get deleted first when the device runs low on storage. There is no guarantee when these files will be deleted. Note: you should not rely on the system deleting these files for you; you should always have a reasonable maximum, such as 1 MB, for the amount of space you consume with cache files, and prune those files when exceeding that space.
Returns
- The path of the directory holding application cache files.
public void reverse ()
- 因为当调用这个方法时,如果动画正在播放,可以反向播放动画直到回播放的原点。所以我喜欢用它来平滑的结束动画的播放。
Plays the ValueAnimator in reverse. If the animation is already running, it will stop itself and play backwards from the point reached when reverse was called. If the animation is not currently running, then it will start from the end and play backwards. This behavior is only set for the current animation; future playing of the animation will use the default behavior of playing forward.
Android Tips Round-Up, Part 2
- Android开发中这些小技巧你都知道吗?(一)
- Android开发中这些小技巧你都知道吗?(一)
- Android开发中这些小技巧你都知道吗?
- Android开发中这些小技巧你都知道吗?(二)
- Android开发中这些小技巧你都知道吗?(三)
- Android开发中这些小技巧你都知道吗?(四)
- Android开发中这些小技巧你都知道吗?(五)
- Android开发中这些小技巧你都知道吗?(四)
- 自媒体运营和推广的这些小技巧你都知道吗?
- 这些你都知道吗?
- “小程序”定制开发?这些您都知道吗?
- 这些开源项目,你都知道吗?(持续更新中...)
- 学JAVA,这些你都知道吗?(1)
- 这些继承知识你都知道吗?
- 关于链接,这些你都知道吗?
- 这些你都知道?Win7不易发现的小亮点
- 让iOS保持界面流畅的这些技巧,你都知道吗
- Git学习总结(6)——作为一名程序员这些代码托管工具你都知道吗?
- 怎么编写makefile
- 216. Combination Sum III
- 数据结构期末总结
- Mysql日期类型
- 二:Hibernate映射机制
- Android开发中这些小技巧你都知道吗?(一)
- oracle linux 7 安装oracle 12c
- Android四大组件—Service
- 虚拟机系统安装详细步骤(图文)
- 安装windows10中出现的问题
- Json 生成与解析详解及实例代码
- Spring 事务基于注解方式的配置
- 解决quartz的job无法注入spring对象
- [LeetCode]380. Insert Delete GetRandom O(1)