android:capitalize not working

前端 未结 7 1451
Happy的楠姐
Happy的楠姐 2021-02-07 22:16

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

Here\'s the TextView:

 

        
7条回答
  •  情深已故
    2021-02-07 22:40

    In kotlin gives

      private val replacementTransformationMethod: ReplacementTransformationMethod =
        object : ReplacementTransformationMethod() {
            override fun getOriginal(): CharArray {
                return charArrayOf(
                    'a',
                    'b',
                    'c',
                    'd',
                    'e',
                    'f',
                    'g',
                    'h',
                    'i',
                    'j',
                    'k',
                    'l',
                    'm',
                    'n',
                    'o',
                    'p',
                    'q',
                    'r',
                    's',
                    't',
                    'u',
                    'v',
                    'w',
                    'x',
                    'y',
                    'z'
                )
            }
    
            override fun getReplacement(): CharArray {
                return charArrayOf(
                    'A',
                    'B',
                    'C',
                    'D',
                    'E',
                    'F',
                    'G',
                    'H',
                    'I',
                    'J',
                    'K',
                    'L',
                    'M',
                    'N',
                    'O',
                    'P',
                    'Q',
                    'R',
                    'S',
                    'T',
                    'U',
                    'V',
                    'W',
                    'X',
                    'Y',
                    'Z'
                )
            }
        }
    

    then in the block override fun onActivityCreated(savedInstanceState: Bundle?)

    set

    this.textUserCode.transformationMethod = replacementTransformationMethod
    

提交回复
热议问题