2016-03-13 19 views
12

我已經升級到android 6並在嘗試爲某些editText設置驗證時看到一些奇怪的事情。 我使用Android的saripaar進行驗證:Android 6 EditText.setError工作不正常

@Email(messageResId = R.string.error_email) 
private EditText email; 
@Password(min = 6, scheme = Password.Scheme.ALPHA_NUMERIC_MIXED_CASE_SYMBOLS) 
private EditText password; 
@ConfirmPassword 
private EditText repassword; 
@NotEmpty(messageResId = R.string.error_name) 
private EditText firstname; 
@NotEmpty(messageResId = R.string.error_name) 
private EditText lastname; 
private Validator mValidator; 

出於某種原因,電子郵件,密碼,確認密碼不顯示在彈出錯誤信息,而最後和名字都很好

enter image description here

我試過沒有圖書館,發生同樣的問題。 使用editText.setError(「Some Message」) 這並沒有發生在Android 6之前,並且工作正常。5.

任何人都有類似的經歷嗎?如果是的話你是如何解決它的?

+0

我沒有使用該庫,但它看起來像一個主題/風格的問題。 – 323go

+0

嘗試沒有該庫的驗證,看看它是否仍然無效。我看過這個問題,但我認爲這是在Android 4.4和4.3上 - 從未在棉花糖或棒棒糖上。 – Darwind

+0

我在android 5.1和6.0上也有同樣的問題,我沒有使用任何插件進行驗證。這適用於我的Android 4.4。 – jdabrowski

回答

2

使用getString(R.string.error_name)

+0

但問題顯示'messageResId' - ''getString(...)'不會返回一個資源標識符,而是實際的字符串,而且這個庫似乎需要一個資源標識符。 –

1

我認爲這是有關的活動主題,我使用的是什麼,並在Android 6.0的工作:

活動主題:

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"> 
    <!-- Customize your theme here. --> 
    <item name="colorPrimary">@color/colorPrimary</item> 
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item> 
    <item name="colorAccent">@color/colorAccent</item> 
</style> 

代碼:請注意我延伸activity不是AppCompatActivity

myeditText.setError("Please enter valid email"); 
myeditText.setFocusable(true); 
1

TRY @NotEmpty註釋上的電子郵件的EditText場

@NotEmpty 
@Email 
private EditText email;