gpt4 book ai didi

android - 更新当前聚焦的 EditText 的 ImeOptions

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:01:50 24 4
gpt4 key购买 nike

我有一个 EditText,其 ImeOptions 设置为 EditorInfo.IME_ACTION_NEXT。因此,当该字段获得焦点时,“下一步”按钮将显示在键盘上。我希望按钮在用户键入时更改为“完成”(出于某些原因)。所以我有一个 TextWatcher,我尝试将“afterTextChanged”上的 ImeOptions 更改为 EditorInfo.IME_ACTION_DONE,但键盘上的键没有改变。我尝试隐藏键盘,更改 ImeOptions 并再次显示键盘,但它不起作用(此解决方案适用于 iOS)。

有人知道怎么做吗?

最佳答案

我试过这个并且它有效,问题是你有时可以看到键盘何时出现和消失。

@Override
public void afterTextChanged(Editable s) {

if (/*condition*/) {

// Change the IME of the current focused EditText
editText.setImeOptions(EditorInfo.IME_ACTION_DONE);


// Hide the keyboard
hideKeyboard(activity);

// Restart the input on the current focused EditText
InputMethodManager imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
imm.restartInput(editText);

// Show the keyboard
showKeyboard(activity);
}
}

关于android - 更新当前聚焦的 EditText 的 ImeOptions,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37351052/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com