2016-01-20 17 views
5

Tôi có hai phần tử TextInputLayout cạnh nhau: firstname và lastname. Bên dưới chúng tôi có một phần tử có độ rộng đầy đủ là TextInputLayout: email.TextInputLayout EditText nextFocusRight không hoạt động như vậy

Tôi đang cố gắng để ghi đè lên nút bên cạnh trên bàn phím để khi kích Next bên trong đầu vào firstname, nó nên đến LastName đầu vào và từ đó đến e-email vv

Bây giờ vấn đề là khi tôi nhấn Next trên bàn phím, nó sẽ không đến trường lastname mà thay vào đó sẽ gửi e-mail bên dưới nó.

Đây là một phần của tập tin xml của tôi, nơi tôi có ba đầu vào:

<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> 

Tôi cũng đã cố gắng nhắm vào TextInputLayout thay vì EditText nhưng nó không có hiệu lực.

Sự tập trung tiếp theo thậm chí có thể với TextInputLayout hoặc là lỗi hoặc tôi chỉ đang làm điều gì đó rất sai?

+0

Nếu câu trả lời của @Yen Pei Tay không khắc phục được, hãy thử làm theo. http://stackoverflow.com/a/41489258/1015678 –

Trả lời

6

Thay đổi này -> android: nextFocusDown = "@ + id/register_input_lastname"

+0

Haha, nó thực sự hoạt động. Tôi đoán nguyên nhân của việc này là trọng tâm tự động di chuyển xuống và kỹ thuật đầu vào lastname là dưới firstname. Nhưng tôi không hiểu tại sao lại có nextFocusRight etc? Những người đó chỉ làm việc trên các đầu vào EditText thông thường? –

+0

Không có ý tưởng nhưng giá trị một thử. –

+0

tôi không đặt biểu tượng dấu cộng khiến nó không tìm thấy id. thêm cộng là một ý tưởng tốt nhờ. – j2emanue

3

Câu trả lời trên là chính xác, nhưng tôi chỉ cần thêm một cái gì đó khi tôi cố gắng tôi không nhận được sự tập trung tiếp theo dòng như vậy tôi thêm một thuộc tính thêm vào các câu trả lời trên

android: inputType = "đầu vào của bạn gõ vào đây"

sau khi đặt này tôi đã nhận chỉnh sửa văn bản tập trung của tôi vào tới một

dụ

android: inputType = "text" // đặt bất kỳ loại đầu vào theo yêu cầu của bạn

android: nextFocusDown = "@ + id/next_id"

Hoàn dụ của một EditText

<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> 

Hy vọng điều này sẽ giúp những người khác :)

1

tôi đã sử dụng mã này dưới đây nó hoạt động giống như một ma thuật :)

Trên thực tế các trick là

android: imeOptions = "actionNext"

android: nextFocusDown = "@ + id/tilAddress"

android: inputType = "text"

<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> 
Các vấn đề liên quan