editText.setEdtInputType(InputType.TYPE_NUMBER_FLAG_DECIMAL);或者
android:inputType="numberDecimal|number"
再添加
<p><span style="font-family: Arial, Helvetica, sans-serif;">editText.addTextChangedListener(new TextWatcher() {</span></p> public void afterTextChanged(Editable edt) {
String temp = edt.toString();
int posDot = temp.indexOf(".");
if (posDot <= 0) return;
if (temp.length() - posDot - 1 > 2) {
edt.delete(posDot + 3, posDot + 4);
}
}
public void beforeTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {
}
public void onTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {
}
});