Android 開發實現EditText 光標居右顯示
前言:
有些時候肯定會遇到這種奇葩的需求,光標要靠右顯示,因為Android里面光標默認是靠左顯示的,那怎么實現呢,肯定有辦法的,這里提供一種實現方式,看布局
<FrameLayout android:layout_width="match_parent" android:layout_height="wrap_content"> <TextView android:id="@+id/tv" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_marginRight="6dp" android:background="@null" android:gravity="right|center_vertical" android:text="請輸入您想輸入的" /> <EditText android:id="@+id/et" android:layout_width="match_parent" android:layout_height="match_parent" android:gravity="right|center_vertical" /> </FrameLayout>
看布局你就明白是什么意思 了吧,代碼里面監聽EditText輸入,讓TextView顯示隱藏就行了。
et.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) { } @Override public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) { if (TextUtils.isEmpty(charSequence)) { tv.setVisibility(View.VISIBLE); } else { tv.setVisibility(View.GONE); } } @Override public void afterTextChanged(Editable editable) { } });感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!
新聞熱點
疑難解答