android:大写不起作用 [英] android:capitalize not working

查看:112
本文介绍了android:大写不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个TextView。我试图将每个单词中的第一个字母大写。

I have a TextView. I'm trying to capitalize the first letter in every word.

这是TextView:

Here's the TextView:

 <TextView 
            android:text="TextView" 
            android:id="@+id/textView1" 
            android:layout_height="wrap_content" 
            android:layout_width="wrap_content" 
            android:layout_alignParentRight="true" 
            android:textSize="30dip" 
            android:textStyle="bold" 
            android:layout_marginRight="5dip" 
            android:ellipsize="end"
            android:capitalize="words">
        </TextView>

以下是我添加文字的方式:

Here's how I'm adding the text:

TextView titleView = (TextView) findViewById(R.id.textView1);
    titleView.setText( section.replace("_", " ") );

我是否可以动态添加文本并期望将文字大写?是否有另一个特征干扰 android:capitalize android:capitalize 已损坏?

Can I not add text dynamically and expect it to capitalize the words? Is another trait interfering with android:capitalize? Is android:capitalize broken?

感谢您的回复。

推荐答案

大写基本上只是一个 KeyListener ,你可以设置在XML中,因此它仅适用于用户输入的文本。 正如文档所述(强调我的):

capitalize is basically just a KeyListener that you can set in XML, so it only applies to text input by the user. As the documentation states (emphasis mine):


如果设置,则指定此TextView具有文本输入方法,并应自动大写用户键入的内容

如何将Java中每个单词的首字母大写,这有一些有用的答案。

There is a related question on how to capitalize the first letter of every word in Java which has some helpful answers.

这篇关于android:大写不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆