gpt4 book ai didi

android - 添加 fragment 后应用程序崩溃

转载 作者:太空宇宙 更新时间:2023-11-03 11:06:05 25 4
gpt4 key购买 nike

我正在添加这个 https://github.com/rockerhieu/emojicon lib 到我的应用程序,现在这个 lib 要求我向我的布局添加 fragment View

<fragment
android:id="@+id/emojicons"
android:layout_width="match_parent"
android:layout_height="220dp"
class="com.rockerhieu.emojicon.EmojiconsFragment"/>

添加这个后我的应用程序崩溃了,你能帮我解决这个问题吗?这是登录

Caused by: android.view.InflateException: Binary XML file line #90: Error inflating class fragment

最佳答案

你应该用它来编辑文本

<github.ankushsachdeva.emojicon.EmojiconEditText
android:id="@+id/emojicon_edit_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_weight="8"
emojicon:emojiconSize="28sp" />

然后在初始化 emojitext 后的类文件中,你将不得不使用这些监听器

    final EmojiconsPopup popup = new EmojiconsPopup(rootView, this);
//Will automatically set size according to the soft keyboard size
popup.setSizeForSoftKeyboard();

/*--------------------------------------------------------------------*/

popup.setOnDismissListener(new PopupWindow.OnDismissListener() {

@Override
public void onDismiss() {
changeEmojiKeyboardIcon(emojiButton, R.mipmap.smiley);
}
});

//If the text keyboard closes, also dismiss the emoji popup
popup.setOnSoftKeyboardOpenCloseListener(new EmojiconsPopup.OnSoftKeyboardOpenCloseListener() {

@Override
public void onKeyboardOpen(int keyBoardHeight) {

}

@Override
public void onKeyboardClose() {
if (popup.isShowing())
popup.dismiss();
}
});

/*On emoji clicked, add it to edittext*/
popup.setOnEmojiconClickedListener(new EmojiconGridView.OnEmojiconClickedListener() {

@Override
public void onEmojiconClicked(Emojicon emojicon) {
if (emojiconEditText == null || emojicon == null) {
return;
}

int start = emojiconEditText.getSelectionStart();
int end = emojiconEditText.getSelectionEnd();
if (start < 0) {
emojiconEditText.append(emojicon.getEmoji());
} else {
emojiconEditText.getText().replace(Math.min(start, end),
Math.max(start, end), emojicon.getEmoji(), 0,
emojicon.getEmoji().length());
}
}
});

//On backspace clicked, emulate the KEYCODE_DEL key event
popup.setOnEmojiconBackspaceClickedListener(new EmojiconsPopup.OnEmojiconBackspaceClickedListener() {

@Override
public void onEmojiconBackspaceClicked(View v) {
KeyEvent event = new KeyEvent(
0, 0, 0, KeyEvent.KEYCODE_DEL, 0, 0, 0, 0, KeyEvent.KEYCODE_ENDCALL);
emojiconEditText.dispatchKeyEvent(event);
}
});


// To toggle between text keyboard and emoji keyboard keyboard(Popup)
emojiButton.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View v) {

//If popup is not showing => emoji keyboard is not visible, we need to show it
if (!popup.isShowing()) {

//If keyboard is visible, simply show the emoji popup
if (popup.isKeyBoardOpen()) {
popup.showAtBottom();
changeEmojiKeyboardIcon(emojiButton, R.mipmap.ic_action_keyboard);
}

//else, open the text keyboard first and immediately after that show the emoji popup
else {
emojiconEditText.setFocusableInTouchMode(true);
emojiconEditText.requestFocus();
popup.showAtBottomPending();
final InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
inputMethodManager.showSoftInput(emojiconEditText, InputMethodManager.SHOW_IMPLICIT);
changeEmojiKeyboardIcon(emojiButton, R.mipmap.ic_action_keyboard);
}
}

//If popup is showing, simply dismiss it to show the undelying text keyboard
else {
popup.dismiss();
}
}
});

希望这对你有帮助:)

关于android - 添加 fragment 后应用程序崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33522889/

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