首页 > 解决方案 > 当 EditText 处于非活动状态时如何设置提示位置

问题描述

当我在我的 EditText 中调整了一些不活动的值时,它看起来如下图所示: 在此处输入图像描述

当我从处于非活动状态的 EditText 中删除一个值时,它看起来像这样:

在此处输入图像描述

是否可以设置 TextInputLayer 或 TextInputEditText 的某些属性以在非活动状态下获得行为,如下所示: 在此处输入图像描述

标签: androidxamarin.android

解决方案


我认为这是TextInputEditTextwith的默认行为TextInputLayout,有属性可以直接设置它,但是您可以通过进行一些设置来做到这一点,作为一种解决方法:

你可以FocusChange给它添加事件,当它不在焦点时," "给它设置一个(空值):</p>

TextInputEditText textInputEditText = FindViewById<TextInputEditText>(Resource.Id.editText);

textInputEditText.FocusChange += delegate
         {
             if (!textInputEditText.IsFocused)
             {
                 if (string.IsNullOrEmpty( textInputEditText.Text))
                 {
                     textInputEditText.Text = " ";
                 }
             }
             else
             {
                 if (textInputEditText.Text == " ")
                 {
                     textInputEditText.Text = "";
                 }
             }
         };

推荐阅读