久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

編輯 OTP 的文本,每個字母位于不同的位置

Edit text for OTP with Each letter in separate positions(編輯 OTP 的文本,每個字母位于不同的位置)
本文介紹了編輯 OTP 的文本,每個字母位于不同的位置的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

限時送ChatGPT賬號..

我正在開發(fā)一個應(yīng)用程序,當(dāng)用戶想要重置他的密碼時要求 OTP, 所有這些都以 horizo??ntal 方向的線性布局排列,具有一定的邊距和最大長度為 1,因此每個 editText 中只能輸入一個字母...這是正確的 方法嗎?? 有什么建議嗎??

I'm working on a application which asks for OTP when user want to reset his password for which I need a text like the one in attached Image... What I thought to proceed with is individual editText for each of the letter, All of them arranged in linear layout of horizontal orientation with some margin and max length as 1 so only one letter can be entered in each editText... Is that a right Approach?? Any Suggestions??

推薦答案

在所有這些答案之后,我沒有找到我想要的,因為考慮到 UI/UX,元素的刪除存在缺陷,以至于返回上一個 EditText,當(dāng)前 EditText 不應(yīng)為空.

After all of these answers, I didn't find what I wanted as considering the UI/UX, the deletion of element was flawed in such a way that to go back to previous EditText, current EditText should not be empty.

這是我在 Kotlin 中實現(xiàn)的解決方案,它適用于按鍵盤上的 Delete 鍵刪除.另外,刪除功能是這樣實現(xiàn)的,當(dāng)當(dāng)前 EditText 為空并按下 Delete 鍵時,它會切換回之前的 EditText 并刪除其元素.

Here's the solution I've implemented in Kotlin which works for Deletion by the Delete Key, pressed on the keyboard. Also, the delete function is implemented as such that when the current EditText is empty and Delete key is pressed, it switches back to previous EditText and delete its element also.

  1. 這樣調(diào)用函數(shù):

  1. Call the functions as such:

//GenericTextWatcher here works only for moving to next EditText when a number is entered
//first parameter is the current EditText and second parameter is next EditText
editText1.addTextChangedListener(GenericTextWatcher(editText1, editText2))
editText2.addTextChangedListener(GenericTextWatcher(editText2, editText3))
editText3.addTextChangedListener(GenericTextWatcher(editText3, editText4))
editText4.addTextChangedListener(GenericTextWatcher(editText4, null))

//GenericKeyEvent here works for deleting the element and to switch back to previous EditText
//first parameter is the current EditText and second parameter is previous EditText
editText1.setOnKeyListener(GenericKeyEvent(editText1, null))
editText2.setOnKeyListener(GenericKeyEvent(editText2, editText1))
editText3.setOnKeyListener(GenericKeyEvent(editText3, editText2))
editText4.setOnKeyListener(GenericKeyEvent(editText4,editText3))

  • 現(xiàn)在,將這兩個類粘貼到您當(dāng)前的類中

  • Now, paste these two classes in your current class

    class GenericKeyEvent internal constructor(private val currentView: EditText, private val previousView: EditText?) : View.OnKeyListener{
        override fun onKey(p0: View?, keyCode: Int, event: KeyEvent?): Boolean {
            if(event!!.action == KeyEvent.ACTION_DOWN && keyCode == KeyEvent.KEYCODE_DEL && currentView.id != R.id.editText1 && currentView.text.isEmpty()) {
                //If current is empty then previous EditText's number will also be deleted
                previousView!!.text = null 
                previousView.requestFocus()
                return true
            }
            return false
        }
    
    
    }
    
    class GenericTextWatcher internal constructor(private val currentView: View, private val nextView: View?) : TextWatcher {
        override fun afterTextChanged(editable: Editable) { // TODO Auto-generated method stub
            val text = editable.toString()
            when (currentView.id) {
                R.id.editText1 -> if (text.length == 1) nextView!!.requestFocus()
                R.id.editText2 -> if (text.length == 1) nextView!!.requestFocus()
                R.id.editText3 -> if (text.length == 1) nextView!!.requestFocus()
                //You can use EditText4 same as above to hide the keyboard
            }
        }
    
        override fun beforeTextChanged(
            arg0: CharSequence,
            arg1: Int,
            arg2: Int,
            arg3: Int
        ) { // TODO Auto-generated method stub
        }
    
        override fun onTextChanged(
            arg0: CharSequence,
            arg1: Int,
            arg2: Int,
            arg3: Int
        ) { // TODO Auto-generated method stub
        }
    
    }
    

  • 此外,要禁用可見光標(biāo),您可以在 Layout 的 EditText 標(biāo)記中使用 android:cursorVisible="false" 或使用 java 函數(shù) setCursorVisible(false).

    Further, to disable the visible cursor, you can either use android:cursorVisible="false" in your EditText tag in the Layout or can use the java function setCursorVisible(false).

    編輯:我使用的是股票小部件EditTexts,所以如果你想在它們周圍顯示一個框,只需創(chuàng)建一個可繪制布局并將其設(shè)置為EditTexts 并給它們 5dp 的填充.這將創(chuàng)建一個盒子,讓它看起來更酷.

    Edit: I'm using stock widget EditTexts so if you want to display a box around them, just create a drawable layout and set it as background of EditTexts and give them a padding of 5dp. This will create a box and will make it look cooler.

    這篇關(guān)于編輯 OTP 的文本,每個字母位于不同的位置的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

    【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!

    相關(guān)文檔推薦

    Cut, copy, paste in android(在android中剪切、復(fù)制、粘貼)
    android EditText blends into background(android EditText 融入背景)
    Change Line Color of EditText - Android(更改 EditText 的線條顏色 - Android)
    EditText showing numbers with 2 decimals at all times(EditText 始終顯示帶 2 位小數(shù)的數(shù)字)
    Changing where cursor starts in an expanded EditText(更改光標(biāo)在展開的 EditText 中的開始位置)
    EditText, adjustPan, ScrollView issue in android(android中的EditText,adjustPan,ScrollView問題)
    主站蜘蛛池模板: 日韩在线成人 | 日韩在线不卡视频 | 色婷婷av久久久久久久 | 中文在线a在线 | 国产视频线观看永久免费 | 狠狠做深爱婷婷综合一区 | 欧美专区在线 | 一区二区三区在线播放视频 | 国产激情视频在线 | 九色网址 | 久草福利 | 亚洲成人免费 | av在线播放免费 | 精品一区二区久久久久久久网站 | 亚洲中午字幕 | 久久久涩 | 亚洲www啪成人一区二区麻豆 | 欧美日韩一区二区三区视频 | 久久精品国产亚洲 | 中文字幕久久精品 | 人人操日日干 | 一二区视频 | 国产精品国产三级国产aⅴ中文 | 污片在线观看 | 青草福利| 国产又爽又黄的视频 | 91资源在线观看 | 在线观看www视频 | 久久久成人一区二区免费影院 | 午夜精品一区二区三区在线播放 | 99福利视频| 色综合久久天天综合网 | 在线观看一区 | 国产成人高清成人av片在线看 | 亚洲欧洲一区二区 | 99国产精品99久久久久久 | 国产精品无 | 免费看a | 日韩精品视频一区二区三区 | 亚洲视频免费在线播放 | 国产情侣啪啪 |