gpt4 book ai didi

android如何在edittext中制作文本完全固定的行

转载 作者:太空狗 更新时间:2023-10-29 15:38:53 25 4
gpt4 key购买 nike

我想允许用户只输入 5 行,我试过了

<EditText
android:layout_below="@+id/tv_signup_descriptionError"
android:id="@+id/et_signup_description"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dip"
android:hint="@string/et_hint_enterDescription"
android:singleLine="false"
android:lines="5"
android:gravity="top"
android:scrollHorizontally="false"
android:inputType="textMultiLine"
android:maxLines="5"/>

但我仍然可以在第五行之后按 Enter

最佳答案

@Swayam 你是对的,但是这个解决方案已经改进了:

1- 更好的性能

2- 在您的解决方案中,如果您输入了 7 行(您的最大输入行数),然后在顶行中按下回车键,最后一行将被删除,但在此解决方案中,“输入”键已被忽略。

 mEditText.setOnKeyListener(new View.OnKeyListener() {

@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {

if (keyCode == KeyEvent.KEYCODE_ENTER && event.getAction() == KeyEvent.ACTION_DOWN) {

if ( ((EditText)v).getLineCount() >= 7 )
return true;
}

return false;
}
});

关于android如何在edittext中制作文本完全固定的行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14672234/

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