Android 開發(fā)實(shí)現(xiàn)EditText 光標(biāo)居右顯示
Android 開發(fā)實(shí)現(xiàn)EditText 光標(biāo)居右顯示
前言:
有些時(shí)候肯定會(huì)遇到這種奇葩的需求,光標(biāo)要靠右顯示,因?yàn)锳ndroid里面光標(biāo)默認(rèn)是靠左顯示的,那怎么實(shí)現(xiàn)呢,肯定有辦法的,這里提供一種實(shí)現(xiàn)方式,看布局
<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="請(qǐng)輸入您想輸入的" /> <EditText android:id="@+id/et" android:layout_width="match_parent" android:layout_height="match_parent" android:gravity="right|center_vertical" /> </FrameLayout>
看布局你就明白是什么意思 了吧,代碼里面監(jiān)聽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) { } });
感謝閱讀,希望能幫助到大家,謝謝大家對(duì)本站的支持!
相關(guān)文章
Android開發(fā)VR實(shí)戰(zhàn)之播放360度全景視頻
這篇文章主要為大家詳細(xì)介紹了Android開發(fā)VR實(shí)戰(zhàn)之播放360度全景視頻,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-12-12Android編程中Perferences的用法實(shí)例分析
這篇文章主要介紹了Android編程中Perferences的用法,以實(shí)例形式較為詳細(xì)的分析了配置文件preferences.xml的功能、定義及使用方法,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2015-11-11Android LinearLayout實(shí)現(xiàn)自動(dòng)換行
這篇文章主要為大家詳細(xì)介紹了Android LinearLayout實(shí)現(xiàn)自動(dòng)換行,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-08-08Android實(shí)現(xiàn)拍照、選擇相冊(cè)圖片并裁剪功能
這篇文章主要為大家詳細(xì)介紹了Android實(shí)現(xiàn)拍照、選擇相冊(cè)圖片并裁剪功能的相關(guān)資料,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-12-12Android Toast實(shí)現(xiàn)全屏顯示
這篇文章主要為大家詳細(xì)介紹了Android Toast實(shí)現(xiàn)全屏顯示,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-08-08AndriodStudio使用listview實(shí)現(xiàn)簡(jiǎn)單圖書管理
這篇文章主要為大家詳細(xì)介紹了AndriodStudio使用listview實(shí)現(xiàn)簡(jiǎn)單圖書管理,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-03-03Android WebView的使用方法及與JS 相互調(diào)用
這篇文章主要介紹了Android WebView的使用方法及與JS 相互調(diào)用的相關(guān)資料,WebView 是 Android 中一個(gè)非常實(shí)用的組​件, WebView 可以使得網(wǎng)頁(yè)輕松的內(nèi)嵌到app里,還可以直接跟js相互調(diào)用,需要的朋友可以參考下2017-07-07