【问题标题】:How to specify min and/or max length in RemoteInput如何在 RemoteInput 中指定最小和/或最大长度
【发布时间】:2017-03-28 14:01:16
【问题描述】:

我在我的 Android N 通知中使用 RemoteInput。

我想为输入设置最小和最大文本长度限制。

Google Hangouts 得到了这个(即当用户输入至少 1 个字符时发送按钮启用)。任何人都知道如何做到这一点?我尝试查看 Android 文档,但没有成功。

【问题讨论】:

  • OK min length of 1 似乎是自动的。但我仍然无法设置最大长度。

标签: android notifications remote-input


【解决方案1】:
 button.setClickable(false);
    button.setEnabled(false);
    editText = (EditText)findViewById(R.id.editText);


    editText.addTextChangedListener(new TextWatcher() {
        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            button.setClickable(true);
            button.setTextColor(getResources().getColor(R.color.colorPrimary));
            // TODO Auto-generated method stub
        }

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            // TODO Auto-generated method stub
        }

        @Override
        public void afterTextChanged(Editable s) {

            // TODO Auto-generated method stub
        }
    });



}

【讨论】:

  • 如何按照您上面的建议获得 RemoteInput 按钮:button.setClickable(false)?
  • 按钮按钮 = (Button)findViewById(R.id.button2); button.setClickable(false);或者你可以通过你的 xml 文件来完成。 button.setEnable(false) 是您逻辑的重要部分。 @Henrik
【解决方案2】:

尝试使用自定义视图实现通知。并在其中包含您需要的所有逻辑。 对我来说这是一种方式((

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-12-11
    • 2019-07-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-02-29
    • 1970-01-01
    相关资源
    最近更新 更多