当点击“空格"时,防止EditText转到新行 [英] Prevent EditText from going to new line when 'Space' is tapped

查看:90
本文介绍了当点击“空格"时,防止EditText转到新行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要一个EditText,它是多行和句子的首字母大写.我正在使用:

I want to have an EditText which is multi Line and First Letter of a Sentence to be capital. I'm using:

<EditText
        android:id="@+id/editText2"
        android:layout_width="300dp"
        android:layout_height="150dp"
        android:layout_alignParentStart="true"
        android:layout_alignParentTop="true"
        android:layout_marginStart="32dp"
        android:layout_marginTop="67dp"
        android:background="#ddebed"
        android:ems="10"
        android:inputType="textMultiLine|textCapSentences"
        android:singleLine="false"
        android:text="@string/same" />

我可以同时实现:MultiLine和CapSentences. 但是,当我在单词后面按空格键"时,它会换行. 我该如何预防?

I can acheive both: MultiLine and CapSentences. But, When I press 'Space key' after a word, It goes to a new line. How do I prevent it?

android:text="@string/same"指的是<string name="same">\n \n \n Regards: Principal</string> 因此,问题是由 \ n 引起的. 我想要一个EditText,在下一行中有一些已经键入的文本,并允许用户在前n行中输入一些文本.

The android:text="@string/same" refers to <string name="same">\n \n \n Regards: Principal</string> So, The problem is being caused by \n's. I want to have an EditText which has some already typed text in next Line, And Allow User to enter some text in First 'n' lines.

推荐答案

您可以在\ n之前添加两个隐藏的空格. 要添加隐藏的空间,请执行以下操作:Alt + 0160(数字键). 因此,当用户键入内容时,隐藏空间将继续移动,并且用户文本将无法到达\ n.

You can Add Two Hidden Spaces Before \n's. To add a Hidden space: Alt + 0160 (Numpad keys). So, When User is typing something, The Hidden Spaces will keep moving and UserText won't be able to reach to \n.

这篇关于当点击“空格"时,防止EditText转到新行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆