android 代码设置居右_Android 开发实现EditText 光标居右显示
Android 開發實現EditText 光標居右顯示
前言:
有些時候肯定會遇到這種奇葩的需求,光標要靠右顯示,因為Android里面光標默認是靠左顯示的,那怎么實現呢,肯定有辦法的,這里提供一種實現方式,看布局
android:layout_width="match_parent"
android:layout_height="wrap_content">
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="請輸入您想輸入的" />
android:id="@+id/et"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="right|center_vertical" />
看布局你就明白是什么意思 了吧,代碼里面監聽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) {
}
});
感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!
總結
以上是生活随笔為你收集整理的android 代码设置居右_Android 开发实现EditText 光标居右显示的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: python调用键盘_使用 Python
- 下一篇: maven 公共模块依赖_idea 创建