我有一个要求设置为谷歌钱包格式的金额。当用户在edittext中输入金额时。它将显示如下所示的金额。我已经搜索了很多,但没有得到任何解决方案。如果有人能帮助me.Its,对我有很大的帮助。
发布于 2017-05-11 21:59:38
您可以有一个EditText,并在用户键入文本时将文本格式化为HTML.我不确定你怎么知道用户什么时候在打字,但代码可能是这样的:
editText.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
@Override
public void afterTextChanged(Editable editable) {
if (editable.length() > 1) {
String htmlCode = doSomeMagicHereAndReturnFormattedString(editable.toString());
Spanned spannedHtml;
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N) {
spannedHtml = Html.fromHtml(htmlCode, Html.FROM_HTML_MODE_LEGACY);
} else {
spannedHtml = Html.fromHtml(htmlCode);
}
editText.setText(spannedHtml);
}
}
private String doSomeMagicHereAndReturnFormattedString(String s) {
// You need to change this to be formatted properly
String myHtml = "<html>" + s + "</html>";
return myHtml;
}
});https://stackoverflow.com/questions/43889976
复制相似问题