gpt4 book ai didi

android - 如何在 fragment 中获取 Root View ?

转载 作者:塔克拉玛干 更新时间:2023-11-02 22:54:51 29 4
gpt4 key购买 nike

我正在使用这个库在我的应用程序上使用表情符号键盘。 https://github.com/ankushsachdeva/emojicon

自述文件指出,您的 Activity 布局层次结构的最顶层 View 必须用于初始化弹出窗口。

我的应用是通过 fragment 实现的。

这是我用于测试的代码:

public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {

View view = inflater.inflate(R.layout.overview1_layout, container,
false);

// Give the topmost view of your activity layout hierarchy. This will be used to measure soft keyboard height
EmojiconsPopup popup = new EmojiconsPopup(view, getActivity());

//Will automatically set size according to the soft keyboard size
popup.setSizeForSoftKeyboard();

popup.showAtBottom();


return view;
}

如果我运行这段代码,我会在 logcat 中收到以下错误:

11-02 22:37:16.685: E/AndroidRuntime(30363): java.lang.RuntimeException: Unable to resume activity {com.Testing.full/com.Testing.full.MainActivity}: android.view.WindowManager$BadTokenException: Unable to add window -- token null is not valid; is your activity running?

编辑:我正在使用 SherlockFragment

最佳答案

将 View 保存为fragment 的实例成员,并在OnViewCreated 方法中初始化Emojicons Popup。这可能会解决您的问题。

public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {

View view = inflater.inflate(R.layout.overview1_layout, container,
false);

this.view = view

return view;
}

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);

// Give the topmost view of your activity layout hierarchy. This will be used to measure soft keyboard height
EmojiconsPopup popup = new EmojiconsPopup(view, getActivity());




//Will automatically set size according to the soft keyboard size
popup.setSizeForSoftKeyboard();

popup.showAtBottom();
}

但对于问题标题 - 检查 here

关于android - 如何在 fragment 中获取 Root View ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26704782/

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