gpt4 book ai didi

android - TextInputEditText 使用自定义设计下划线修复字符长度

转载 作者:行者123 更新时间:2023-11-29 02:40:51 27 4
gpt4 key购买 nike

我想设计如下:

在输入用户输入之前:

enter image description here

用户输入数字

enter image description here

是否可以扩展 TextInputEditText 来实现这个请求?

我一直在寻找设计讨论,

how can i underline each character in edittext?

Can I underline text in an android layout?

但是好像不太符合我的要求。

起初我想我会使用letterSpacing,但是下划线有问题。同样对于不同的屏幕分辨率和字体大小,letterSpacing 可能是问题所在,它不能放在一行中。我需要确保它在一行中。

有什么建议可以实现吗?如果有更好的方法,我想避免使用四个编辑文本来实现,是否可以在一个编辑文本中进行修改?

最佳答案

试试这个我的 friend

像这样创建一个 xml 布局文件

                <LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="30dp"
android:layout_marginLeft="60dp"
android:layout_marginRight="60dp"
android:layout_marginTop="20dp"
android:orientation="horizontal"
android:weightSum="4">

<EditText
android:id="@+id/edDigit1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:hint="1"
android:imeOptions="actionNext"
android:inputType="number"
android:maxLength="1" />

<EditText
android:id="@+id/edDigit2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:hint="2"
android:imeOptions="actionNext"
android:inputType="number"
android:maxLength="1" />

<EditText
android:id="@+id/edDigit3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:hint="3"
android:imeOptions="actionNext"
android:inputType="number"
android:maxLength="1" />

<EditText
android:id="@+id/edDigit4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:hint="4"
android:imeOptions="actionNext"
android:inputType="number"
android:maxLength="1" />

</LinearLayout>

**now in your activity file**

EditText edDigit1, edDigit2, edDigit3, edDigit4;
edDigit1 = (EditText) findViewById(R.id.edDigit1);
edDigit2 = (EditText) findViewById(R.id.edDigit2);
edDigit3 = (EditText) findViewById(R.id.edDigit3);
edDigit4 = (EditText) findViewById(R.id.edDigit4);

edDigit1.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {

}

@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
if (edDigit1.getText().toString().equals("")) {
edDigit1.requestFocus();
} else {
edDigit2.requestFocus();
}

}

@Override
public void afterTextChanged(Editable s) {

}
});
edDigit2.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {

}

@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
if (edDigit2.getText().toString().equals("")) {
edDigit2.requestFocus();
} else {
edDigit3.requestFocus();
}

}

@Override
public void afterTextChanged(Editable s) {

}
});
edDigit3.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {

}

@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
if (edDigit3.getText().toString().equals("")) {
edDigit3.requestFocus();
} else {
edDigit4.requestFocus();
}


}

@Override
public void afterTextChanged(Editable s) {

}
});

关于android - TextInputEditText 使用自定义设计下划线修复字符长度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44276145/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com