我想在 Android 控件中进行文本来回交互。这个想法是有这样的东西:
This is some text output by the program.
What is your name? |
将光标置于 |
(请注意,编辑不会从最后一行的开头开始)。然后用户可以自由输入文本(使用任何 Android 输入法、键盘等),但到目前为止不允许更改任何输出。理想情况下,用户输入的样式会有所不同。
然后,一旦输入换行符,我希望程序得到通知并停止编辑:
This is some text output by the program.
What is your name? Foo Bar
Hello, Foo Bar!
请注意,这需要是一个适当的控件,即我可以与其他控件组合以使其成为应用程序主布局的一部分。
最佳答案
将 TextView
和 EditText
并排放置,然后您的问题就解决了,并在 EditText
中添加以下代码行。
android:singleLine= 'true';
EditText
只允许输入一行。让我知道这是否是您的期望。
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="What is your Name?"
android:id="@+id/textView"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="true"
android:id="@+id/editText"
android:layout_alignParentTop="true"
android:layout_toEndOf="@+id/textView" />
</RelativeLayout>
关于android - 具有单个可编辑行的 TextView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35740593/