我有一個Edittext,用戶在其中輸入他們的10位數的手機號碼。我希望當用戶完成輸入10位數字時,drawableRight應該是可見的。我怎樣才能做到這一點呢?
DrawableRight最初是隱藏/不可見的。
另一種方法是,當觸摸到編輯文本時,可以看到可畫的右鍵。
請幫助我。
<LinearLayout
android:id="@ id/list1mobile"
android:layout_width="411dp"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginLeft="8dp"
android:layout_marginTop="3dp"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:orientation="horizontal"
android:padding="10dp"
app:layout_constraintEnd_toEndOf="@ id/list1email"
app:layout_constraintStart_toStartOf="@ id/list1email"
app:layout_constraintTop_toBottomOf="@ id/list1email">
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="start"
android:orientation="垂直"
android:paddingLeft="24dp"
android:paddingStart="24dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_marginTop="1dp"
android:fontFamily="@font/avenibook"
android:inputType="none"
android:text="手機號碼"
android:textAllCaps="false"
android:textColor="@color/blue"
android:textSize="12sp"
android:textStyle="bold" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_marginTop="1dp"
android:fontFamily="@font/avenibook"
android:inputType="none"
android:text=" 91 "
android:textColor="@color/white"
android:textSize="16sp"
android:textStyle="bold" />
<編輯文本
android:id="@ id/mobiledes"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="2dp"
android:layout_marginTop="1dp"
android:fontFamily="@font/avenirltsdoman"
android:inputType="數字"
android:maxLength="10"
android:maxLines="1"
android:background="@null"
android:hint="輸入手機號碼"
android:textColorHint="#87888A"
android:textColor="@color/white"
android:textSize="16sp"
android:textStyle="粗體"
android:drawableRight="@drawable/ic_verifybutton"
android:layout_marginStart="2dp"
android:drawableEnd="@drawable/ic_verifybutton"
android:drawablePadding="2dp"/>
</LinearLayout>
</LinearLayout>
uj5u.com熱心網友回復:
你不能為此使用線性布局,因為線性布局將所有的設計都放在線性中,所以你不能把它放在可畫的地方。
CodePudding
考慮將編輯文本中的輸入型別改為Phone。如果你希望它在開始的位置,請將R.drawable.your_icon的位置改為第一個引數。
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) {
//隱藏可畫性
if(editText.getText().toString().length()!=10)
editText.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0)。
//顯示可繪制的內容
否則
editText.setCompoundDrawablesWithIntrinsicBounds(0,0,R.drawable.your_icon, 0)。
}
@Override
public void afterTextChanged(Editable s) {
}
});
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/313070.html
標籤:
