一般情况下设置button的setText会使被设置的英文字符串全都变为大写,应该在button的xml属性中添加如下属性,才能得到想要的自定义的大小写效果:

android:textAllCaps="false"

或者在程序中设置:

mButton.setTransformationMethod(null);

我在apache.lang工具包中看到capitalize的源码,改良了一下,写了下面这个仅首字母大写的函数:

    /**     * capitalize only the first char, the other chars in the string will be converted to lower case     * 

*

     * TextU.capitalizeOnlyFirstChar(null)  = null     * TextU.capitalizeOnlyFirstChar("")    = ""     * TextU.capitalizeOnlyFirstChar("cat") = "Cat"     * TextU.capitalizeOnlyFirstChar("cAtCh ME") = "Catch me"     * 
*

*

* Created by KyleCe on 2015/12/23. * * @author KyleCe * KyleCe@github */ public static String capitalizeOnlyFirstChar(String str) { int strLen; if (str == null || (strLen = str.length()) == 0) { return str; } return new StringBuilder(strLen) .append(Character.toTitleCase(str.charAt(0))) .append(str.substring(1).toLowerCase()) .toString(); }

have fun

转载署源-By-KyleCe:http://blog.csdn.net/KyleCeshen/article/details/50428143

更多相关文章

  1. 如何实现android button事件?
  2. Android(安卓)打开输入法,中文模式没有候选栏的问题
  3. TextView 相关属性
  4. Android:style和theme
  5. power_supply子系统笔记
  6. android动态获取TextView的属性(width、height、line)
  7. Android中关于Task的一些认识
  8. TextView一行显示一个文字效果
  9. 《Android(安卓)Dev Guide》系列教程9:用户界面之声明布局

随机推荐

  1. 安卓实现标题和按钮在一行,按钮靠最右边布
  2. Android应用开发攻略
  3. 解决Android(安卓)SDK Manager更新、下载
  4. Android(安卓)Q适配(4)-------针对后台 Act
  5. 将网页变成灰色(只限IE)
  6. Android自定义属性 attr format取值类型
  7. android之帧动画实现
  8. Android设置全屏隐藏状态栏的方法
  9. Android(安卓)Studio 修改Logcat的颜色
  10. Android软件版本更新