我试图在单击按钮时隐藏键盘。
然后我遇到了这段代码:
public static void hideKeyboardFrom(Context context, View view) {
InputMethodManager imm = (InputMethodManager) context.getSystemService(Activity.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
}
我的问题是 view.getWindowToken()
是什么?它的意义是什么,它返回了什么。
最佳答案
所以基本上所有的图形用户界面都是在我们所说的 上呈现的。窗口 .一个例子是 Activity
,来自 official documentation :
Almost all activities interact with the user, so the Activity class takes care of creating a window for you in which you can place your UI with setContentView(View)
另一个例子是
AlertDialog
.Android 中的一个屏幕可能有多个窗口。例如,您可以在多窗口 Android 功能中使用两个 Activity 。有时一个窗口可以包含其他窗口。
这是 question有一些关于 的好答案窗口是。
为了回答您的问题,每个窗口都有一个唯一标识符。此标识符称为窗口 token 。所以,一个“WindowToken”的意义就是唯一标识一个Window。
还有一种方法,即
getApplicationWindowToken()
,可用于获取最顶层窗口的标识符。
关于android - android中的 "view.getWindowToken"是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64429296/