2023年7月7日发(作者:)
Android:字母⼤⼩写转换版权声明:本⽂为博主原创⽂章,未经博主允许不得转载。 /ceovip/article/details/78051302在某些特殊场合,要求输⼊⼤写字母。我们可以对输⼊的EditText进⾏设置,不管⽤户输⼊⼤写或者⼩写字母,都⾃动转换为⼤写。代码很简单,⽰例如下:package ndlowertransform;import ty;import ;import ementTransformationMethod;import xt;public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { te(savedInstanceState); setContentView(ty_main); EditText etInput = (EditText) findViewById(t); //限制只输⼊⼤写字母的地⽅,⼩写⾃动转换为⼤写 nsformationMethod(new InputCapLowerToUpper()); } class InputCapLowerToUpper extends ReplacementTransformationMethod{ @Override protected char[] getOriginal() { char[] lower = { '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' }; return lower; } @Override protected char[] getReplacement() { char[] upper = { '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' }; return upper; } }}⼤写转换为⼩写也可以类似的来实现。
发布者:admin,转转请注明出处:http://www.yc00.com/web/1688677903a161791.html
评论列表(0条)