gpt4 book ai didi

Android软键盘监听器?

转载 作者:行者123 更新时间:2023-11-29 17:17:36 25 4
gpt4 key购买 nike

enter image description here

我想听这个红色按钮,怎么办?

最佳答案

对于 Activity :

final View activityRootView = findViewById(R.id.activityRoot);
activityRootView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
Rect r = new Rect();

activityRootView.getWindowVisibleDisplayFrame(r);

int heightDiff = view.getRootView().getHeight() - (r.bottom - r.top);
if (heightDiff > 100) {
//enter code when show keyboard
}else{
//enter code when hide keyboard
}
}
});

对于 fragment :

view = inflater.inflate(R.layout.live_chat_fragment, null);
view.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
Rect r = new Rect();
//r will be populated with the coordinates of your view that area still visible.
view.getWindowVisibleDisplayFrame(r);

int heightDiff = view.getRootView().getHeight() - (r.bottom - r.top);
if (heightDiff > 500) { // if more than 100 pixels, its probably a keyboard...
//enter code when show keyboard
}else{
//enter code when hide keyboard
}
}
});

关于Android软键盘监听器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38119950/

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