gpt4 book ai didi

android - 在android中的键盘上实现弹出窗口以在自定义键盘中添加图像

转载 作者:搜寻专家 更新时间:2023-11-01 09:45:56 44 4
gpt4 key购买 nike

此键盘可以从键盘列表中选择,用户可以在任何应用程序中使用它。只需实现弹出窗口即可在自定义软键盘的键盘上添加图像

最佳答案

您必须创建一个扩展 PopupWindow 的类

public class CustomPopup extends PopupWindow {
Context mContext;
View rootView;

public CustomPopup(View rootView, Context mContext){
super(mContext);
this.mContext = mContext;
this.rootView = rootView;
View customView = createCustomView();
setContentView(customView);
setSoftInputMode(LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
setSize(250, LayoutParams.MATCH_PARENT);
}

private View createCustomView(){
LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view = inflater.inflate(R.layout.custom_popup, null, false);

return view;
}

public void setSize(int width, int height){
setWidth(width);
setHeight(height);
}

}

然后在你的软键盘类中使用它

CustomPopup popupWindow;

public View onCreateInputView() {
final View root = getLayoutInflater().inflate(R.layout.input, null);

popupWindow = new CustomPopup(root, this);

return root;
}

这是显示弹出窗口的方法。注意 mInputView 是你的 keyboardView 变量

private void showPopup() {
int height = mInputView.getHeight();
popupWindow.setSize(LayoutParams.MATCH_PARENT, height);
popupWindow.showAtLocation(mInputView.getRootView(), Gravity.BOTTOM, 0, 0);
final InputMethodManager mInputMethodManager = (InputMethodManager) getBaseContext()
.getSystemService(Context.INPUT_METHOD_SERVICE);
mInputMethodManager.showSoftInput(mInputView, 0);
}

关于android - 在android中的键盘上实现弹出窗口以在自定义键盘中添加图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38110602/

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