我正在寻找一种将字符串的第一个字母转换为小写字母的方法。我正在使用的代码从数组中提取随机String,在文本 View 中显示该字符串,然后使用它显示图像。数组中的所有字符串的首字母都大写,但是存储在应用程序中的图像文件当然不能大写。
String source = "drawable/"
//monb is randomly selected from an array, not hardcoded as it is here
String monb = "Picture";
//I need code here that will take monb and convert it from "Picture" to "picture"
String uri = source + monb;
int imageResource = getResources().getIdentifier(uri, null, getPackageName());
ImageView imageView = (ImageView) findViewById(R.id.monpic);
Drawable image = getResources().getDrawable(imageResource);
imageView.setImageDrawable(image);
谢谢!
最佳答案
if (monb.length() <= 1) {
monb = monb.toLowerCase();
} else {
monb = monb.substring(0, 1).toLowerCase() + monb.substring(1);
}