在我的应用程序中,我想输入带有常规字符和表情符号快捷方式的文本。
从软键盘输入字符时,我想启动一个带有一系列图标/表情符号的弹出菜单或弹出窗口。按图标/表情符号将在光标处插入表情符号的快捷字符。
可以使用普通字符和表情符号短字符的文本。在文中显示表情符号是更进一步的。
答案 0 :(得分:0)
我喜欢的解决方案是:
1 - 点击笑脸按钮后,我会弹出一个弹出窗口:
@Override
public void onClick(View v) {
switch( v.getId()) {
case R.id.fragment_log_popup_smileys:
PopupIcons popup = new PopupIcons( myActivity, new PopupIconResultHandler() {
@Override
public void iconClicked( String iconResult) {
logTextV.getText().insert( logTextV.getSelectionStart(), iconResult);
}
});
popup.show();
break;
任何笑脸字符都会插入文字中。它们可以显示为相同的表情。容易这样做。
2 - 弹出窗口
public class PopupIcons implements Serializable {
Activity myActivity;
PopupIconResultHandler myClickHandler;
public PopupIcons( final Activity activityContext, PopupIconResultHandler clickHandler) {
myActivity = activityContext;
myClickHandler = clickHandler;
}
public void show() {
Rect rectgle= new Rect();
Window window= myActivity.getWindow();
window.getDecorView().getWindowVisibleDisplayFrame( rectgle);
int StatusBarHeight= rectgle.top;
int contentViewTop= window.findViewById( Window.ID_ANDROID_CONTENT).getTop();
int TitleBarHeight= contentViewTop - StatusBarHeight;
Display display = ((WindowManager) myActivity.getSystemService( Context.WINDOW_SERVICE)).getDefaultDisplay();
LinearLayout viewGroup = (LinearLayout) myActivity.findViewById( R.id.popupIconsLinearLayout);
LayoutInflater layoutInflater = (LayoutInflater) myActivity.getSystemService( Context.LAYOUT_INFLATER_SERVICE);
View layout = layoutInflater.inflate( R.layout.popup_icons, viewGroup);
// Creating the PopupWindow
final PopupWindow popup = new PopupWindow( myActivity);
popup.setContentView(layout);
popup.setFocusable(true);
popup.setAnimationStyle( R.style.PopupMenu);
popup.setWidth( FrameLayout.LayoutParams.WRAP_CONTENT);
popup.setHeight(FrameLayout.LayoutParams.WRAP_CONTENT);
View.OnClickListener handler = new View.OnClickListener() {
@Override
public void onClick( View v) {
if( myClickHandler != null) {
myClickHandler.iconClicked( (String) v.getTag());
}
popup.dismiss();
}
};
ImageButton but = (ImageButton) layout.findViewById( R.id.popup_icon_smile); but.setOnClickListener( handler);
but = (ImageButton) layout.findViewById( R.id.popup_icon_smile_big); but.setOnClickListener( handler);
but = (ImageButton) layout.findViewById( R.id.popup_icon_smile_cool); but.setOnClickListener( handler);
// etc ... for all buttons
popup.showAtLocation( layout, Gravity.BOTTOM | Gravity.LEFT, 30 , 30);
}
}
我喜欢这种方法。 你有改进的建议吗?