将Android EditText格式化为HH:MM:SS

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了将Android EditText格式化为HH:MM:SS相关的知识,希望对你有一定的参考价值。

我在android studio中有一个编辑文本,我希望从用户那里获得小时,分钟和秒的值。我怎样才能从编辑文本开始说00:00:00,并输入用户输入的数字,但保持:完好无损?

我宁愿不要求用户自己输入分号

答案

你可以使用MaskedEditText

的build.gradle

dependencies {
    compile 'com.vicmikhailau:MaskedEditText:2.0.3'
}

添加xml

<com.vicmikhailau.maskededittext.MaskedEditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:mask="your_mask" />

enter image description here

以上是关于将Android EditText格式化为HH:MM:SS的主要内容,如果未能解决你的问题,请参考以下文章