Edit text for OTP with Each letter in separate positions

后端 未结 19 1042
别跟我提以往
别跟我提以往 2020-12-13 00:25

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 wi

19条回答
  •  甜味超标
    2020-12-13 00:46

    For the question asked by @SachinMandhare on https://stackoverflow.com/a/57337907/8765580

    Just modify the code to

    String pattern = "";
    for (int j = 0; j < getText().toString().length(); j++) {
        pattern += "*"; //Any Character that you want to display 
    }
    for (int i = 0; i < mNumChars; i++) {
        canvas.drawLine(startX, bottom, startX + mCharSize, bottom, mLinesPaint);
        if (getText().length() > i) {
             float middle = startX + mCharSize / 2;
             canvas.drawText(pattern, i, i + 1, middle - textWidths[0] / 2, bottom - mLineSpacing, getPaint());
        }
        if (mSpace < 0) {
            startX += mCharSize * 2;
        } else {
            startX += mCharSize + mSpace;
        }
    }
    

提交回复
热议问题