[英]Format in edittext 00:00
在Android Studio中,我希望有一個使用00:00
格式的Edittext,而您不必在00:00
鍵入:
。 有什么方法可以在布局中完成,還是應該以編程方式完成?
謝謝!
如果您願意使用外部庫,建議您搜索許多MaskedEditTexts庫之一。 我在我的一個項目中使用過edittext-mask ,這很簡單:
1-將其添加到您的proyect:
compile 'ru.egslava:MaskedEditText:1.0.5'
2-使用MaskedEditText代替常規的Android的EditText:
<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="1234567890"
mask:mask="##:###"
android:hint="12:34"
app:keep_hint="true"
/>
希望能幫助到你 :)
嘗試這個
在xml中執行此操作
<EditText
android:id="@+id/editText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:maxLength="5" />
並在addTextChangedListener
中添加到edittext
editText = (EditText)findViewById(R.id.editText);
editText.addTextChangedListener(new TextWatcher()
{
public void afterTextChanged(Editable s)
{
}
public void beforeTextChanged(CharSequence s, int start, int count, int after)
{
}
public void onTextChanged(CharSequence s, int start, int before, int count)
{
String text = editText.getText().toString();
textlength = editText.getText().length();
if(textlength == 2)
{
editText.setText(text + ":");
}
}
});
這將為您工作。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.