pbootcms网站模板|日韩1区2区|织梦模板||网站源码|日韩1区2区|jquery建站特效-html5模板网

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

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

問題描述

限時送ChatGPT賬號..

我正在開發一個應用程序,當用戶想要重置他的密碼時要求 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,當前 EditText 不應為空.

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 中實現的解決方案,它適用于按鍵盤上的 Delete 鍵刪除.另外,刪除功能是這樣實現的,當當前 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. 這樣調用函數:

  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))

  • 現在,將這兩個類粘貼到您當前的類中

  • 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
        }
    
    }
    

  • 此外,要禁用可見光標,您可以在 Layout 的 EditText 標記中使用 android:cursorVisible="false" 或使用 java 函數 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,所以如果你想在它們周圍顯示一個框,只需創建一個可繪制布局并將其設置為EditTexts 并給它們 5dp 的填充.這將創建一個盒子,讓它看起來更酷.

    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.

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

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

    相關文檔推薦

    Cut, copy, paste in android(在android中剪切、復制、粘貼)
    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 位小數的數字)
    Changing where cursor starts in an expanded EditText(更改光標在展開的 EditText 中的開始位置)
    EditText, adjustPan, ScrollView issue in android(android中的EditText,adjustPan,ScrollView問題)
    主站蜘蛛池模板: 安平县鑫川金属丝网制品有限公司,声屏障,高速声屏障,百叶孔声屏障,大弧形声屏障,凹凸穿孔声屏障,铁路声屏障,顶部弧形声屏障,玻璃钢吸音板 | 铝机箱_铝外壳加工_铝外壳厂家_CNC散热器加工-惠州市铂源五金制品有限公司 | 洁净棚-洁净工作棚-无菌室-净化工程公司_北京卫护科技有限公司 | 山东氧化铁红,山东铁红-淄博科瑞化工有限公司 | 山东齐鲁漆业有限公司【官网】-工业漆专业生产厂家 | 成都思迪机电技术研究所-四川成都思迪编码器 | 浇注料-高铝砖耐火砖-郑州凯瑞得窑炉耐火材料有限公司 | 中开泵,中开泵厂家,双吸中开泵-山东博二泵业有限公司 | 金现代信息产业股份有限公司--数字化解决方案供应商 | 地埋式垃圾站厂家【佳星环保】小区压缩垃圾中转站转运站 | 重庆私家花园设计-别墅花园-庭院-景观设计-重庆彩木园林建设有限公司 | 耐热钢-耐磨钢-山东聚金合金钢铸造有限公司 | 钢化玻璃膜|手机钢化膜|钢化膜厂家|手机保护膜-【东莞市大象电子科技有限公司】 | 塑料异型材_PVC异型材_封边条生产厂家_PC灯罩_防撞扶手_医院扶手价格_东莞市怡美塑胶制品有限公司 | 亚克隆,RNAi干扰检测,miRNA定量检测-上海基屹生物科技有限公司 | 天空彩票天下彩,天空彩天空彩票免费资料,天空彩票与你同行开奖,天下彩正版资料大全 | 北京发电机出租_发电机租赁_北京发电机维修 - 河北腾伦发电机出租 | 雨水收集系统厂家-雨水收集利用-模块雨水收集池-徐州博智环保科技有限公司 | 阿里巴巴诚信通温州、台州、宁波、嘉兴授权渠道商-浙江联欣科技提供阿里会员办理 | 合肥网络推广_合肥SEO网站优化-安徽沃龙First | 北京网络营销推广_百度SEO搜索引擎优化公司_网站排名优化_谷歌SEO - 北京卓立海创信息技术有限公司 | 柔性测斜仪_滑动测斜仪-广州杰芯科技有限公司 | 知名电动蝶阀,电动球阀,气动蝶阀,气动球阀生产厂家|价格透明-【固菲阀门官网】 | 卡诺亚轻高定官网_卧室系统_整家定制_定制家居_高端定制_全屋定制加盟_定制家具加盟_定制衣柜加盟 | 温泉机设备|温泉小镇规划设计|碳酸泉设备 - 大连连邦温泉科技 | 刑事律师_深圳著名刑事辩护律师_王平聚【清华博士|刑法教授】 | 不锈钢轴流风机,不锈钢电机-许昌光维防爆电机有限公司(原许昌光维特种电机技术有限公司) | 冷热冲击试验箱_温度冲击试验箱价格_冷热冲击箱排名_林频厂家 | 上海盐水喷雾试验机_两厢式冷热冲击试验箱-巨怡环试 | 不锈钢电动球阀_气动高压闸阀_旋塞疏水调节阀_全立阀门-来自温州工业阀门巨头企业 | 气动隔膜泵-电动隔膜泵-循环热水泵-液下排污/螺杆/管道/化工泵「厂家」浙江绿邦 | 塑料检查井_双扣聚氯乙烯增强管_双壁波纹管-河南中盈塑料制品有限公司 | 东莞办公家具厂家直销-美鑫【免费3D效果图】全国办公桌/会议桌定制 | 香蕉筛|直线|等厚|弧形|振动筛|香蕉筛厂家-洛阳隆中重工 | 大型冰雕-景区冰雕展制作公司,3D创意设计源头厂家-[赛北冰雕] | 加热制冷恒温循环器-加热制冷循环油浴-杭州庚雨仪器有限公司 | 附着力促进剂-尼龙处理剂-PP处理剂-金属附着力处理剂-东莞市炅盛塑胶科技有限公司 | 品牌广告服务平台,好排名,好流量,好生意。| 品牌广告服务平台,好排名,好流量,好生意。 | 高扬程排污泵_隔膜泵_磁力泵_节能自吸离心水泵厂家-【上海博洋】 | 绿萝净除甲醛|深圳除甲醛公司|测甲醛怎么收费|培训机构|电影院|办公室|车内|室内除甲醛案例|原理|方法|价格立马咨询 |