我也没有提到textInput.我的意思是,一旦你在一个TextView具有静态文本(从数据库调用填充到用户输入的数据(可能不是大写)),我怎么能确保他们的资本?
谢谢!
Che*_*mon 156
我应该能够通过标准的java字符串操作来实现这一点,没有特定的Android或TextView.
就像是:
String upperString = myString.substring(0,1).toUpperCase() + myString.substring(1);
Run Code Online (Sandbox Code Playgroud)
虽然可能有一百万种方法可以实现这一目标.请参阅字符串文档
Bet*_*das 64
android:inputType="textCapSentences"
Run Code Online (Sandbox Code Playgroud)
要么
TV.sname.setInputType(InputType.TYPE_TEXT_FLAG_CAP_SENTENCES);
Run Code Online (Sandbox Code Playgroud)
这将是CAP的第一个字母.
要么
compile 'org.apache.commons:commons-lang3:3.4' //in build.gradle module(app)
tv.setText(StringUtils.capitalize(myString.toLowerCase().trim()));
Run Code Online (Sandbox Code Playgroud)
nol*_*man 22
StringBuilder sb = new StringBuilder(name);
sb.setCharAt(0, Character.toUpperCase(sb.charAt(0)));
return sb.toString();
Run Code Online (Sandbox Code Playgroud)
您可以
在Gradle中添加Apache Commons Langcompile 'org.apache.commons:commons-lang3:3.4'
并使用 WordUtils.capitalizeFully(name)
小智 7
对于Kotlin,只需致电
textview.text = string.capitalize()
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
88144 次 |
| 最近记录: |