如何避免人们使用我在文本框中不支持的其他字符?

问题描述 投票:0回答:1

我只想在我的iOS / Android应用程序中支持以下ascii字符:

 <!--
CharacterRegions control what letters are available in the font. Every
character from Start to End will be built and made available for drawing. The
default range is from 32, (ASCII space), to 126, ('~'), covering the basic Latin
character set. The characters are ordered according to the Unicode standard.
See the documentation for more information.
-->
<CharacterRegions>
  <CharacterRegion>
  <Start>&#32;</Start>
  <End>&#512;</End>
  </CharacterRegion>
  <CharacterRegion>
  <!-- Apostrophe 8217 -->
  <Start>&#8216;</Start>
  <End>&#8222;</End>
  </CharacterRegion>
  <CharacterRegion>
  <!-- Currency symbols -->
  <Start>&#8352;</Start>
  <End>&#8378;</End>
  </CharacterRegion>
</CharacterRegions>

是否有可能在我的应用程序中禁用所有其他ascii字符,以便人们只能在我的应用程序的软键盘上选择受支持的字符?

我只想支持英语,西班牙语,意大利语,法语,德语和葡萄牙语字符,以及一些特殊字符,例如货币符号。我不希望有人可以使用亚洲字符。

如何避免人们使用我在文本框中不支持的其他字符?

是否可以禁用某些软键盘按钮,使播放器无法使用它们,或者在玩家使用软键盘输入它们之后是否总是需要检查文本框字符是否受支持?

c# android ios xna monogame
1个回答
0
投票

是的,这是可能的。您只需要一个TextWatcher。

textField.addTextChangedListener(new TextWatcher() {
    @Override
    public void onTextChanged(CharSequence s, int start, int before, int count) {

    // Check to make sure the new text entered 
    // matches your requirements, otherwise, 
    // remove it from the text field.

    }

    @Override
    public void beforeTextChanged(CharSequence s, int start, int count, int after) {

    // TODO Auto-generated method stub
    }

    @Override
    public void afterTextChanged(Editable s) {

    // TODO Auto-generated method stub
    }
});
© www.soinside.com 2019 - 2024. All rights reserved.