首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >从弹出式窗口/菜单中添加带有表情符号的文本和表情符号(字符)

从弹出式窗口/菜单中添加带有表情符号的文本和表情符号(字符)
EN

Stack Overflow用户
提问于 2015-08-14 12:35:59
回答 1查看 278关注 0票数 0

在我的应用程序中,我想用普通字符和表情快捷键输入文本。

当在软键盘上输入字符时,我想用一系列图标/表情启动弹出菜单或弹出窗口。按下图标/表情符号将在光标处插入表情短距离字符。

有正常字符和表情-短切字符的文本是可以的。在文本中显示表情是进一步的一步。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-09-23 17:38:10

我喜欢的解决办法是:

1-单击笑脸按钮后,我启动弹出:

代码语言:javascript
复制
@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-弹出式窗口

代码语言:javascript
复制
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);   
}

}

我喜欢这种方法。你有改进的建议吗?

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/32010275

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档