[英]how to create customized edittextbox android?
我正在嘗試制作自定義的編輯textbox
。 當得到一串數字時,我想像這樣呈現它們:
而不是像這樣的常規方式:
我嘗試了一些方法,但沒有一個給我像上面的圖片那樣的結果,我沒有更多的想法。
你知道如何簡單地創建它嗎?
現在我正在使用按鈕小部件:
<Button
android:id="@+id/licenceplatecontainer"
android:layout_width="@dimen/licenceplate_width"
android:layout_height="@dimen/licenceplate_height"
android:layout_alignParentTop="true"
android:layout_centerInParent="true"
android:layout_marginBottom="20dp"
android:layout_marginTop="5dp"
android:background="@drawable/rectangle"
android:text="00-000-00"
android:textSize="45sp" />
但問題是,當我從用戶那里獲取號碼並設置文本時:
Button btnLicencePlate = (Button) findViewById(R.id.licenceplatecontainer);
btnLicencePlate.setText(txtLicenceplate.getText().toString());
我正在失去模式。
有一個很好的掩碼編輯文本可以滿足您的需要。
但也許您需要對該 EditText 進行一些修改,使其看起來像 TextView。 例如,為該組件使用 TextView 樣式並使其無法聚焦。
android 中的edittext 沒有默認掩碼。 相反,您可以使用此處提供的 Custom 類。
並簡單地使用
EditText phone = (EditText)findViewById(R.id.phone);
phone.addTextChangedListener(new MaskedWatcher("(###) ###-##-##"))
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.