表情符号弹出窗口的大小不正确
Emoji popup has not the right size
我实现了这个表情符号键盘:
https://github.com/ankushsachdeva/emojicon
但现在看起来像这样:
在右侧,您可以看到弹出窗口不合适。它并没有完全覆盖键盘。左侧、右侧和底部的键盘仍有一些蓝色。甚至可能有点高。
我认为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>
我几乎可以肯定这里的问题是 shadow-border 围绕着你的 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));
从弹出窗口中删除背景。
我实现了这个表情符号键盘: https://github.com/ankushsachdeva/emojicon
但现在看起来像这样:
在右侧,您可以看到弹出窗口不合适。它并没有完全覆盖键盘。左侧、右侧和底部的键盘仍有一些蓝色。甚至可能有点高。
我认为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>
我几乎可以肯定这里的问题是 shadow-border 围绕着你的 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));
从弹出窗口中删除背景。