Android 开发中常见bug 总结

密码形式 EditText 的 Hint 字体显示 异常

EditText password = (EditText) findViewById(R.id.register_password_text);
password.setTypeface(Typeface.DEFAULT);
password.setTransformationMethod(new PasswordTransformationMethod());

参考:
http://stackoverflow.com/questions/3406534/password-hint-font-in-android

TextView设置ellipsize=”end”省略号后面还有字

 android:ellipsize="end"
 android:maxLines="2"

效果图

原因:textview中包含了回车或者html字符
解决办法:
- myText.replaceAll("\\<.*?>","")
或者
- Html.fromHtml(myText).toString())

参考:
http://stackoverflow.com/questions/17131294/strange-issue-with-androidellipsize-end

warning: CRLF will be replaced by LF…..

在git提交的时候出现了这个错误,产生这个问题是因为在windows、Linux和Mac在处理文件换行时的标示符不一致。windows使用CRLF作为结束符,而Linux和Mac使用LF作为结束符。

如果刚从windows转到mac 开发,会遇到此错误,反之,则会出现warning: LF will be replaced by CRLF…..

解决办法:我们可以通过terminal.app 或者cmd 查看自己的git配置

$ git config core.autocrlf

如果显示true,则git会在提交的时候自动帮我们处理换行。可通过如下代码更改设置

$ git config --global core.autocrlf  true

路径错误

 Error:(1, 0) Your project path contains non-ASCII characters. This will most likely
cause the build to fail on Windows. Please move your project to a different
directory. See http://b.android.com/95744 for details.

This warning can be disabled by using the command line flag
-Dcom.android.build.gradle.overridePathCheck=true, or adding the line
‘com.android.build.gradle.overridePathCheck=true’ to gradle.properties file
in the project directory.

导入或者新建androidstudio项目的时候,路径中包含了中文,去掉中文即可!!

java.lang.IllegalStateException: Cannot add header view to list – setAdapter has already been called.

解决方法:在setAdapter之前执行addHeaderView方法

public void addHeaderView(View v, Object data, boolean isSelectable) {  

    // 只要mAdapter不为空就抛出此异常  
    if (mAdapter != null && ! (mAdapter instanceof HeaderViewListAdapter)) {  
        throw new IllegalStateException(  
                "Cannot add header view to list -- setAdapter has already been called.");  
    }  
  //......  
}  

TextView中英文混排提前换行的问题

这个问题是Android系统本身的bug,没有很好的解决办法,有说是全角半角的问题,有说用JustifyTextView可以解决问题,也有通过自定义控件解决问题的.比如如下这种情况

中英文混排提前换行

最终TextView中英文排版混乱 这篇博文在一定程度上解决了我的问题,感谢.遇到同样问题的可以看看

主要思路是通过一个list将所有的字符存起来,再canvas.drawtext来解决问题.

java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState

抛出这个异常的原因是试图在activity的状态已经保存之后提交FragmentTransaction,导致activity状态丢失.

解决建议:

  1. onCreate()中或者FragmentActivity#onResumeFragments()或者Activity#onPostResume()commit
  2. 避免在接口回掉中执行操作,如AsyncTask#onPostExecute()
  3. 使用commitAllowingStateLoss()来提交

详细介绍:Fragment Transactions & Activity State Loss

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值