gpt4 book ai didi

android - Android 中 EditText 的掩码

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:05:10 25 4
gpt4 key购买 nike

我想在 EditText 中限制除数字以外的所有符号的输入,“?”和 ”*”。我怎么能做到?

最佳答案

如果您的字符串也有最大严格长度,则可以使用掩码。我不确定这是正确的解决方案,但这是最简单的解决方案。在 Android Studio 的 Android 程序中使用掩码的一种简单方法是使用 MaskedEditText 库 ( GitHub link )。

我不明白什么意思:数字、“?”还有“”,所以我想只是“?”和“”。所以代码是:

在你的 build.gradle 中:

compile 'ru.egslava:MaskedEditText:1.0.5'

在你的布局中:

<br.com.sapereaude.maskedEditText.MaskedEditText
android:id="@+id/phone_input"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="phone"
android:typeface="monospace"
mask:allowed_chars="?*"
mask:mask="##########"
app:keep_hint="true"
/>

此代码创建了一个只能包含“?”的 EditText。和“*”,最大长度为 10。欢迎提问 :-)

关于android - Android 中 EditText 的掩码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5854814/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com