修改BUG
修改飘屏,飘屏不合适
This commit is contained in:
@@ -51,79 +51,18 @@ public class CurrencyExchangeActivity extends BaseMvpActivity<CurrencyExchangePr
|
||||
mBinding.t5.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (walletBean == null){
|
||||
return;
|
||||
}
|
||||
float earnings_num = Float.parseFloat(walletBean.getEarnings());
|
||||
int earnings_num_int = (int) Math.floor(earnings_num);
|
||||
// 获取 earnings 值
|
||||
String earnings = truncateToFirstDecimalPlace(walletBean.getEarnings());
|
||||
mBinding.etCustomAmount.setText(earnings);
|
||||
mBinding.etCustomAmount.setText(earnings_num_int+"");
|
||||
}
|
||||
});
|
||||
|
||||
TextInputEditText etCustomAmount = mBinding.etCustomAmount;
|
||||
|
||||
// 限制只能输入数字和小数点后一位
|
||||
etCustomAmount.setKeyListener(DigitsKeyListener.getInstance("0123456789."));
|
||||
etCustomAmount.setFilters(new InputFilter[]{ (source, start, end, dest, dstart, dend) -> {
|
||||
// 防止输入负号
|
||||
if (source.toString().contains("-")) {
|
||||
return "";
|
||||
}
|
||||
|
||||
String newText = dest.toString().substring(0, dstart) + source.toString() + dest.toString().substring(dend);
|
||||
|
||||
// 检查小数点
|
||||
if (newText.contains(".")) {
|
||||
String[] splitResult = newText.split("\\.");
|
||||
if (splitResult.length > 1 && splitResult[1].length() > 1) {
|
||||
// 小数点后只能有一位
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
// 可选:限制最大长度
|
||||
if (newText.length() > 10) {
|
||||
return "";
|
||||
}
|
||||
|
||||
return null;
|
||||
}});
|
||||
|
||||
// 可选:添加 TextWatcher 来监听输入内容变化
|
||||
etCustomAmount.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 s) {
|
||||
// 如果以小数点开头,自动补 0
|
||||
if (s.toString().startsWith(".")) {
|
||||
s.insert(0, "0");
|
||||
}
|
||||
// 如果以多个 0 开头,只保留一个
|
||||
if (s.toString().startsWith("0") && s.toString().length() > 1 && s.toString().charAt(1) != '.') {
|
||||
s.delete(0, 1);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
private String truncateToFirstDecimalPlace(String value) {
|
||||
if (TextUtils.isEmpty(value)) return "0.0";
|
||||
|
||||
int dotIndex = value.indexOf('.');
|
||||
if (dotIndex == -1) {
|
||||
return value + ".0"; // 没有小数点,默认加 .0
|
||||
}
|
||||
|
||||
String integerPart = value.substring(0, dotIndex);
|
||||
String decimalPart = value.substring(dotIndex + 1);
|
||||
|
||||
if (decimalPart.length() >= 1) {
|
||||
return integerPart + "." + decimalPart.charAt(0); // 只取小数点后一位
|
||||
} else {
|
||||
return integerPart + ".0"; // 小数点后为空,默认加 0
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getLayoutId() {
|
||||
@@ -139,6 +78,7 @@ public class CurrencyExchangeActivity extends BaseMvpActivity<CurrencyExchangePr
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
MvpPre.wallet();
|
||||
MvpPre.getWalletConfig();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user