Kar*_*urg 7 android android-edittext android-textinputlayout
我有两个TextInputLayout元素并排:名字和姓氏.在他们下面我有另一个全宽度TextInputLayout元素:电子邮件.
我正在尝试覆盖键盘上的下一个按钮,这样当在firstname输入中单击Next时,它应该转到lastname输入并从那里转到电子邮件等.
现在的问题是,当我在键盘上按下Next时,它不会转到lastname字段,而是转到它下面的电子邮件.
这是我的xml文件的一部分,我有这三个输入:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_gravity="center_horizontal"
android:baselineAligned="false">
<android.support.design.widget.TextInputLayout
android:id="@+id/input_layout_firstname"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1">
<EditText
android:id="@+id/register_input_firstname"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/hint_firstname"
android:inputType="textCapSentences"
android:nextFocusForward="@+id/register_input_lastname"
android:nextFocusRight="@+id/register_input_lastname" />
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:id="@+id/input_layout_lastname"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1">
<EditText
android:id="@+id/register_input_lastname"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/hint_lastname"
android:inputType="textCapSentences"
android:nextFocusDown="@+id/register_input_email" />
</android.support.design.widget.TextInputLayout>
</LinearLayout>
<android.support.design.widget.TextInputLayout
android:id="@+id/input_layout_email"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:id="@+id/register_input_email"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/hint_email"
android:inputType="textEmailAddress" />
</android.support.design.widget.TextInputLayout>
Run Code Online (Sandbox Code Playgroud)
我也试过瞄准TextInputLayout而不是EditText但没有效果.
下一个焦点甚至是可能的,TextInputLayout或者它是一个错误还是我只是做了一些非常错误的事情?
小智 8
我在下面使用这个代码,它的工作就像一个魔术:)
实际上诀窍是
机器人:imeOptions = "actionNext"
机器人:nextFocusDown = "@ + ID/tilAddress"
安卓的inputType ="文本"
<android.support.design.widget.TextInputLayout
android:id="@+id/tilSchoolName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/margin_small">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="@dimen/text_size_small"
android:textColor="@color/colorTxt"
android:maxLines="1"
android:imeOptions="actionNext"
android:nextFocusDown="@+id/tilAddress"
android:inputType="text"
android:hint="School Name" />
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:id="@+id/tilAddress"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="@dimen/text_size_small"
android:textColor="@color/colorTxt"
android:maxLines="1"
android:hint="Address" />
</android.support.design.widget.TextInputLayout>
Run Code Online (Sandbox Code Playgroud)
上面的答案是正确的,但我只需要在我尝试时添加一些内容我没有将焦点移到下一行,所以除了上面的答案之外,我还添加了一个属性
android:inputType="你的输入类型在这里"
把这个放在我的编辑文本焦点到下一个
例子
android:inputType="text"//根据您的要求设置任何输入类型
android:nextFocusDown="@+id/next_id"
编辑文本的完整示例
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:hintTextAppearance="@style/TextAppearence.App.TextInputLayout"
android:textColorHint="@color/hint">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:maxLines="1"
android:id="@id/first_name_edt"
android:nextFocusDown="@+id/last_name_edt"
android:imeOptions="actionNext"
android:inputType="text"
android:hint="@string/str_first_name" />
</android.support.design.widget.TextInputLayout>
Run Code Online (Sandbox Code Playgroud)
希望这会帮助其他人:)
| 归档时间: |
|
| 查看次数: |
5713 次 |
| 最近记录: |