发表于: 2018-12-12 23:00:49

0 724


一、今天完成的事情

关于Android Studio警告:String literal in setText can not be translated. Use Android resources instead

原因:使用setText()方法时直接传入字符串

官方解释

Android runs on many devices in many regions. To reach the most users, your app should handle text, audio files, numbers, currency, and graphics in ways appropriate to the locales where your app is used.

This document describes best practices for localizing Android apps.

You should already have a working knowledge of the Java programming language and be familiar with Android resource loading, the declaration of user interface elements in XML, development considerations such as activity lifecycle, and general principles of internationalization and localization.

It is good practice to use the Android resource framework to separate the localized aspects of your app as much as possible from the core Java-based functionality:

  • You can put most or all of the contents of your app's user interface into resource files, as described in this document and in Providing Resources.
  • The behavior of the user interface, on the other hand, is driven by your Java-based code. For example, if users input data that needs to be formatted or sorted differently depending on locale, then you would use the Java programming language to handle the data programmatically. This document doesn't cover how to localize your Java-based code.

For a short guide to localizing strings in your app, see the training lesson, Supporting Different Languages.

核心内容有两个:

1. 遵守开发规范,尽量使用资源文件,比如将文本放到values文件夹下的strings.xml文件中,需要使用时直接引用;

2. 当应用需要设置不同的语言时,使用资源文件方便翻译。

所以能遵守规范就尽量遵守规范吧,这样做也确实方便开发,比如应用中有很多地方需要用到字符串“感谢”,如果直接使用字符串,那么当需要将“感谢”变为“谢谢”时,就需要一处一处修改,非常麻烦。但如果引用的是资源文件,那么只需修改资源文件即可。


重新理了一遍登录、注册的逻辑,发现自己以前写的代码有很多逻辑上的问题,以注册为例(登录中的问题注册中都有)

获取验证码伴随有一个倒计时,那么这个倒计时功能究竟该什么时候启动

之前的逻辑:当用户点击获取验证码Button后立即执行倒计时,如果获取成功就不管它了,如果获取失败,就取消倒计时并给出提示。

现在的逻辑:当用户点击获取验证码的Button后先以一个ProgressBar作为过渡,获取成功后再启动倒计时,如果获取失败就给个提示。

前后比较:获取失败后用户很可能会反复点击获取Button,那么在之前的逻辑中就会反复执行  倒计时开始 -->倒计时结束,错误提示 -->倒计时开始 -->倒计时结束,错误提示......

而在现在的额逻辑中,获取失败只会出现一个提示,只有获取成功才会开始倒计时,这也更加贴近倒计时功能的目的。

以上是我的一点总结,如果有问题,还请师兄指正。


二、明天的计划

今天没做支付,明天继续做


三、遇到的问题    

四、收获

回头看看以前的代码,发现有很多问题



返回列表 返回列表
评论

    分享到