【Android】按钮设置字母不全部大写,button set text to lower case; android button settext lowercase programmably
16lz
2021-01-25
一般情况下设置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
更多相关文章
- 如何实现android button事件?
- Android(安卓)打开输入法,中文模式没有候选栏的问题
- TextView 相关属性
- Android:style和theme
- power_supply子系统笔记
- android动态获取TextView的属性(width、height、line)
- Android中关于Task的一些认识
- TextView一行显示一个文字效果
- 《Android(安卓)Dev Guide》系列教程9:用户界面之声明布局