gpt4 book ai didi

java - Android::如何从 Activity 中的所有 View 中删除焦点?

转载 作者:行者123 更新时间:2023-11-30 11:02:44 25 4
gpt4 key购买 nike

我需要一种方法来在启动时从 Activity 中的所有 View 中移除焦点。

这可能吗?



我已经尝试过:

  • android:focusable="true" & android:focusableInTouchMode="true" 添加到我的 Activity 的最上面的布局。虽然这确实确保没有按钮或 EditText 字段成为焦点,但它带来了另一个问题:最上面的布局变得可聚焦,这在使用键盘聚焦 View 时会产生问题。


  • 从与我的 Activity 相关的 java 文件中调用 getWindow().getCurrentFocus().clearFocus()。我尝试从 onResume()onCreate() 函数调用此命令。不幸的是,getWindow().getCurrentFocus() 总是返回 null。

最佳答案

移除 View 上任何按钮或文本的焦点。您应该将它添加到您的 onCreate() 方法中。

this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);

关于java - Android::如何从 Activity 中的所有 View 中删除焦点?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30670455/

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