gpt4 book ai didi

android - 在用户选择后将 Spinner 焦点设置到 Spinner 本身

转载 作者:太空狗 更新时间:2023-10-29 13:53:27 30 4
gpt4 key购买 nike

当我打开 TalkBack 时,在微调器中做出选择后,焦点会立即返回到屏幕顶部(工具栏)。我希望在用户选择后立即将焦点放在微调器上。

我已经尝试将微调器设置为可聚焦:

spinner.setFocusable(true); 
spinner.setFocusableInTouchMode(true);

我已经查看了以下 StackOverflow 问题和答案,它们并没有直接解决我遇到的问题:

我注意到在设置选择时微调器被短暂禁用。我猜这就是焦点被委托(delegate)给不同 View 的原因。我该如何避免或解决此禁用问题?

如有任何帮助,我们将不胜感激。

最佳答案

我能够通过执行以下操作来解决此问题(希望这可以帮助遇到相同问题的其他人):

    private boolean isUserSelection; // to detect user selection

spinner.setChangeListener(this);
spinner.setFocusable(true);
spinner.setFocusableInTouchMode(true);
if (((AccessibilityManager)getActivity().getSystemService(Context.ACCESSIBILITY_SERVICE)).isEnabled())
{
spinner.setOnFocusChangeListener(new View.OnFocusChangeListener()
{
@Override
public void onFocusChange(View v, boolean hasFocus)
{
if (hasFocus && !isUserSelection)
v.performClick(); //bypasses the caret inside the spinner so user doesn't have to tap twice to open the drop down
else if (!hasFocus && isUserSelection)
v.requestFocus();
}
});
}

在微调器的 itemSelectedListener 中,使用此代码:

if (isUserSelection && (AccessibilityManager)getActivity().getSystemService(Context.ACCESSIBILITY_SERVICE)).isEnabled()))
durationSpinner.requestFocusFromTouch();

关于android - 在用户选择后将 Spinner 焦点设置到 Spinner 本身,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42777009/

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