布局xml文件中有一个TextView,如下所示:
<TextView
android:id="@+id/viewId"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/string_id" />我的字符串指定如下:
<string name="string_id">text</string>有没有可能让它在没有java代码的情况下显示"Text“而不是"text”
(也不改变字符串本身)
发布于 2013-09-04 22:29:59
不是的。但是您可以创建一个简单的CustomView扩展TextView,它覆盖setText并将第一个字母大写成大写字母,就像Ahmad这样说的那样,并在您的setText布局中使用它。
import android.content.Context;
import android.util.AttributeSet;
import android.widget.TextView;
public class CapitalizedTextView extends TextView {
public CapitalizedTextView(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
public void setText(CharSequence text, BufferType type) {
if (text.length() > 0) {
text = String.valueOf(text.charAt(0)).toUpperCase() + text.subSequence(1, text.length());
}
super.setText(text, type);
}
}https://stackoverflow.com/questions/18624273
复制相似问题