2015-10-22 26 views
0

我有一个编辑的文字如下定义:android:imeActionLabel和android:imeOptions在所有设备上都不受尊重。

<android.support.design.widget.TextInputLayout 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:layout_marginTop="15dp"> 

        <EditText 
         android:id="@+id/password" 
         android:layout_width="match_parent" 
         android:layout_height="wrap_content" 
         android:hint="@string/prompt_password" 
         android:imeActionLabel="@string/action_sign_in_short" 
         android:imeOptions="actionUnspecified" 
         android:inputType="textPassword" 
         android:maxLines="1" 
         android:singleLine="true" 
         android:textColor="@color/loginColorPrimaryDark" /> 

       </android.support.design.widget.TextInputLayout> 

在操作按钮,我要开始登录:

edt_password.setOnEditorActionListener(new TextView.OnEditorActionListener() { 
      @Override 
      public boolean onEditorAction(TextView textView, int id, KeyEvent keyEvent) { 
       if (id == R.id.login || id == EditorInfo.IME_NULL) { 
        InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); 
        imm.hideSoftInputFromWindow(textView.getWindowToken(), 
          InputMethodManager.RESULT_UNCHANGED_SHOWN); 
        attemptLogin(); 


        return true; 
       } 
       return false; 
      } 
     }); 

虽然在Nexus 5的设备都工作正常,在索尼设备我得到以下几点:

enter image description here

所以无论是android:imeActionLabel="@string/action_sign_in_short"也不是android:imeOptions="actionUnspecified"正在得到推崇。我很惊讶,我没有自己指定,我在Android Studio中创建项目时在项目模板中选择了一个Login Activity。似乎它坏了!

回答

1

尝试使用下面的代码......对我来说,它正在为所有的设备..希望它会帮助你

<EditText 
      android:id="@+id/password" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_marginTop="10dp" 
      android:hint="@string/hint_password" 
      android:imeOptions="actionDone" 
      android:imeActionLabel="SIGN UP" 
      android:inputType="textPassword" 
      android:padding="10dp" 
      android:singleLine="true" 
      android:textColor="@color/black_color"/> 

confirmPassword.setOnEditorActionListener(new TextView.OnEditorActionListener() { 
      @Override 
      public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { 
       if((event != null && (event.getKeyCode() == KeyEvent.KEYCODE_ENTER)) || (actionId == EditorInfo.IME_ACTION_DONE)) { 
        attemptLogin(); 
        return false; 
       } 
       return false; 
      } 
     }); 
相关问题