TextInputLayout 无法正常工作

TextInputLayout not working correctly

我想在 android.support.design 中使用很棒的设计选项,但是有一个问题。

当我为 TextInputLayout 中的 EditText 的 FocusChanged(setOnFocusChangedListener in android)设置一个动作时,TextInputLayout 无法正常工作并且 浮动文本始终位于带强调色的编辑文本的顶部。(TextInputLayout 不会自行更新)

有什么办法可以解决这个问题吗?!

我正在用 xamarin 制作我的应用程序,但是 没问题 如果你给我 java 代码。

我找到了答案。 不小心,我点击了布局中的一个单选按钮,我看到 TextInputLayout 更新了,浮动标签发生了变化,我发现如果布局刷新,TextInputLayout 也会更新。 所以我只是将其添加到我的 FocusChanged(android 中的 onFocusChangedListener)方法

((TextView)sender).Text = ((TextView)sender).Text;

当您为 EditText 设置自定义 onFocusChangedListener 时,您会覆盖 TextInputLayout 设置的 onFocusChangedListener。因此,无法将 onFocusChangedListenerTextInputLayout.

一起使用

当您为 EditText 设置自定义 onFocusChangedListener 时覆盖了 onFocusChangedListener,这是正确的,但您仍然可以使用旧的 onFocusChangedListener。为此,您需要在覆盖之前获取它。

final View.OnFocusChangeListener oldNameFocusListener = textInputLayout.getEditText().getOnFocusChangeListener();
    textInputLayout.getEditText().setOnFocusChangeListener(new View.OnFocusChangeListener() {
        @Override
        public void onFocusChange(View v, boolean hasFocus) {
            oldNameFocusListener.onFocusChange(v, hasFocus);
        }
    });

这个问题可以在旧的设计库中找到,在新版本(v23.0.0)中,这个问题已经被修复。