表情符号弹出窗口的大小不合适

时间:2016-03-15 11:16:27

标签: android emoji

我实现了这个表情符号键盘: https://github.com/ankushsachdeva/emojicon

但现在它看起来像这样: enter image description here

在右侧,您可以看到弹出窗口不合适。它并不完全覆盖键盘。键盘左侧,右侧和底部仍然有一些蓝色。也许甚至可以在顶部。

我认为 EmojiconsPopup.java

中存在错误
/**
     * Call this function to resize the emoji popup according to your soft keyboard size
     */
    public void setSizeForSoftKeyboard(){
        rootView.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
            @Override
            public void onGlobalLayout() {
                Rect r = new Rect();
                rootView.getWindowVisibleDisplayFrame(r);

                int screenHeight = getUsableScreenHeight();
                int heightDifference = screenHeight - (r.bottom - r.top);
                int resourceId = mContext.getResources()
                        .getIdentifier("status_bar_height", "dimen", "android");
                if (resourceId > 0) {
                    heightDifference -= mContext.getResources().getDimensionPixelSize(resourceId);
                }
                if (heightDifference > 100) {
                    keyBoardHeight = heightDifference;
                    setSize(LayoutParams.MATCH_PARENT, keyBoardHeight);
                    if(isOpened == false){
                        if(onSoftKeyboardOpenCloseListener != null)
                            onSoftKeyboardOpenCloseListener.onKeyboardOpen(keyBoardHeight);
                    }
                    isOpened = true;
                    if(pendingOpen){
                        showAtBottom();
                        pendingOpen = false;
                    }
                }
                else{
                    isOpened = false;
                    if(onSoftKeyboardOpenCloseListener != null)
                        onSoftKeyboardOpenCloseListener.onKeyboardClose();
                }
            }
        });
    }   

我是唯一有此问题的人吗?有人已经修好了吗? 谢谢!

修改 emojicons.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:background="#a16b37"
    android:layout_width="match_parent"
                android:layout_height="match_parent">
    <LinearLayout
            android:id="@+id/emojis_tab"
            android:layout_width="match_parent"
            android:layout_height="50dip"
            android:layout_alignParentTop="true"
            android:orientation="horizontal">
        <ImageButton
                android:background="@null"
                android:layout_width="0dip"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:scaleType="center"
                android:id="@+id/emojis_tab_0_recents"
                android:src="@drawable/ic_emoji_recent_light"/>
        <View
                android:layout_width="1px"
                android:layout_height="match_parent"
                android:background="#382209"/>
        <ImageButton
                android:background="@null"
                android:layout_width="0dip"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:scaleType="center"
                android:id="@+id/emojis_tab_1_people"
                android:src="@drawable/ic_emoji_people_light"/>
        <View
                android:layout_width="1px"
                android:layout_height="match_parent"
                android:background="#382209"/>
        <ImageButton
                android:background="@null"
                android:layout_width="0dip"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:scaleType="center"
                android:id="@+id/emojis_tab_2_nature"
                android:src="@drawable/ic_emoji_nature_light"/>
        <View
                android:layout_width="1px"
                android:layout_height="match_parent"
                android:background="#382209"/>
        <ImageButton
                android:background="@null"
                android:layout_width="0dip"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:scaleType="center"
                android:id="@+id/emojis_tab_3_objects"
                android:src="@drawable/ic_emoji_objects_light"/>
        <View
                android:layout_width="1px"
                android:layout_height="match_parent"
                android:background="#382209"/>
        <ImageButton
                android:background="@null"
                android:layout_width="0dip"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:scaleType="center"
                android:id="@+id/emojis_tab_4_cars"
                android:src="@drawable/ic_emoji_places_light"/>
        <View
                android:layout_width="1px"
                android:layout_height="match_parent"
                android:background="#382209"/>
        <ImageButton
                android:background="@null"
                android:layout_width="0dip"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:scaleType="center"
                android:id="@+id/emojis_tab_5_punctuation"
                android:src="@drawable/ic_emoji_symbols_light"/>
        <View
                android:layout_width="1px"
                android:layout_height="match_parent"
                android:background="#382209"/>
        <ImageButton
                android:background="@null"
                android:layout_width="0dip"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:id="@+id/emojis_backspace"
                android:src="@drawable/sym_keyboard_delete_holo_dark"/>
    </LinearLayout>
    <android.support.v4.view.ViewPager
        android:layout_below="@id/emojis_tab"
        android:id="@+id/emojis_pager"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true" />
    <View
        android:layout_width="match_parent"
        android:layout_height="1px"
        android:layout_below="@id/emojis_tab"
        android:background="#382209"/>
</RelativeLayout>

1 个答案:

答案 0 :(得分:2)

我几乎可以肯定这里的问题是PopUpWindow周围的阴影边框

您可以尝试更改 EmojiconsPopup 构造函数并删除背景:

    public EmojiconsPopup(View rootView, Context mContext){
        super(mContext);
        this.mContext = mContext;
        this.rootView = rootView;
        View customView = createCustomView();
        setContentView(customView);
        setSoftInputMode(LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
        //default size 
        setSize((int) mContext.getResources().getDimension(R.dimen.keyboard_height), LayoutParams.MATCH_PARENT);

        //>>>>>> REMOVE BACKGROUND <<<<<<
        setBackgroundDrawable(new ColorDrawable(0));
    }

这里的关键部分是:

setBackgroundDrawable(new ColorDrawable(0));

从弹出窗口中删除背景。