我需要大写的Android TextView的所有字符 [英] I need to uppercase all characters of Android textview
本文介绍了我需要大写的Android TextView的所有字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我知道如何使用setAllCaps(真),但它要求我使用API14为分钟,我想保持API 9作为分,所以我想知道是否有人已经找到了一种方法,利用所有的所有字符在某些布局textViews?
I know about using setAllCaps(true) but it requires me to use API14 as min, and I would like to keep API 9 as min, so I would like to know if anyone has found a way to capitalize all characters of all textViews in certain layout?
推荐答案
人们可以很容易扩展的TextView
并手动更改文本的情况下在那里。例如:
One could easily extend the TextView
and change the text case there manually. Example:
package com.example.allcapstextview;
import android.content.Context;
import android.util.AttributeSet;
import android.widget.TextView;
import java.util.Locale;
public class AllCapsTextView extends TextView {
private Locale mLocale;
public AllCapsTextView(Context context) {
super(context);
}
public AllCapsTextView(Context context, AttributeSet attrs) {
super(context, attrs);
mLocale = context.getResources().getConfiguration().locale;
}
@Override
public void onFinishInflate() {
super.onFinishInflate();
CharSequence text = getText();
if (text != null) {
text = text.toString().toUpperCase(mLocale);
setText(text);
}
}
}
和布局使用此视图:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="16dp">
<com.example.allcapstextview.AllCapsTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world" />
</RelativeLayout>
这篇关于我需要大写的Android TextView的所有字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文