【问题标题】:How to create emoticons on android如何在android上创建表情符号
【发布时间】:2015-03-06 05:24:20
【问题描述】:

有人可以帮助我理解或指导我阅读有关如何创建表情符号以及它们如何在 android 上工作的阅读材料吗?

我需要从外行与编程的角度了解整个过程。

【问题讨论】:

标签: android emoticons


【解决方案1】:

我们无法创建自己的custom emoticons for generic keyboard in android。因为这些图像存储在form of codesfacebook,skype and other 可能无法实现。我们必须遵循 emoticons See list 中的构建,

如果您想在您的应用中使用它们。使用this

参见thisthis

见软键盘sample here

以及Creating a Custom keyboard上的教程

【讨论】:

  • 忘掉绑定吧,我什至不能创建自定义的 png 并使用它作为表情符号?
  • 假设你最终实现了它。其他社交网站如何知道您发送的 /uu1003d 之类的内容? .当您使用 Skype 发送表情符号时。这些代码存储在两端。您可以在您的应用程序中使用它。如果您的应用在两端都能正常工作
【解决方案2】:

见文章:https://www.androidhive.info/2016/11/android-integrate-emojis-keyboard-app/ 了解表情符号的工作原理以及如何为您的应用实现表情符号功能。

见文章:https://apps.timwhitlock.info/emoji/tables/unicode 确定表情符号的unicode。

您可以从键盘获取输入表情符号。根据您的要求调整它的大小。对于旋转和翻转支持,您可以玩布局,拿着表情符号。

【讨论】:

    【解决方案3】:

    使用自定义库: https://github.com/rockerhieu/emojicon

    public class EmojiKeyboard {
    
        private static final String TAG = "EmojiKeyboard";
        private static final String PREF_KEY_HEIGHT_KB = "EmojiKbHeight";
    
        private Context context;
        private int screenHeight = -1;
        private int emojiKbHeight = -1;
        private PopupWindow emojiKeyboardPopup;
        private View view;
        private SharedPreferences preferences;
    
        public EmojiKeyboard(Context context, View view) {
            if (context instanceof Activity) {
                this.context = context;
                this.view = view;
                preferences = context.getSharedPreferences(context.getString(R.string.app_name), Context.MODE_PRIVATE);
    
                //Restore EmojiKeyboard Height
                emojiKbHeight = preferences.getInt(PREF_KEY_HEIGHT_KB, -1);
    
                //TODO support less then 11 API, and not perfect resizing when switched the keyboard
                view.addOnLayoutChangeListener(new View.OnLayoutChangeListener() {
                    @Override
                    public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) {
                        /*
                        * Get root view height
                        * */
                        screenHeight = screenHeight == -1 && bottom > oldBottom
                                ? bottom
                                : screenHeight;
    
                        /*
                        * Calculate soft keyboard height
                        * */
                        int dHeight = oldBottom - bottom;
                        boolean validHeight = emojiKbHeight == -1 && dHeight > 80 && bottom != oldBottom;
    
                        /*
                        * Сheck twice because the keyboard may have been switched
                        * */
                        emojiKbHeight = validHeight
                                ? dHeight : emojiKbHeight != (dHeight) && dHeight > 0
                                ? dHeight
                                : emojiKbHeight;
    
                        /*
                        * Store emoji keyboard height into SharedPreferences
                        * */
                        preferences.edit().putInt(PREF_KEY_HEIGHT_KB, emojiKbHeight).commit();
    
                        /*
                        * If layout returned to a standard height then dismissing keyboard (OnBackPressed)
                        * */
                        if (screenHeight == bottom) {
                            dismissEmojiKeyboard();
                        }
    
                        /*
                        * Resize emoji on the go when a user switches between keyboards
                        * */
                        resizeEmoji();
                    }
                });
            }
        }
    
    
        public void showEmoji() {
            if (emojiKeyboardPopup == null) {
                createEmojiKeyboard();
            }
            if (!isShowed()) {
                new Handler().postDelayed(new Runnable() {
                    public void run() {
                        emojiKeyboardPopup.showAtLocation(view, Gravity.BOTTOM, 0, 0);
                        resizeEmoji();
                    }
                }, 10L);
    
            } else {
                dismissEmojiKeyboard();
            }
        }
    
        public void createEmojiKeyboard() {
            EmojiView emojiKeyboard = new EmojiView(context, EmojiView.EMOJI_DARK_STYLE, new EmojiView.onEmojiClickListener() {
                public void onBackspace() {
                    if (((Activity) context).getWindow().getCurrentFocus() instanceof EditText) {
                        ((Activity) context).getWindow().getCurrentFocus().dispatchKeyEvent(new KeyEvent(0, 67));
                    }
                }
    
                public void onEmojiSelected(Emojicon emojicon) {
                    if (((Activity) context).getWindow().getCurrentFocus() instanceof EditText) {
                        EmojiView.input((EditText) ((Activity) context).getWindow().getCurrentFocus(), emojicon);
                    }
                }
            });
            emojiKeyboardPopup = new PopupWindow(emojiKeyboard);
            emojiKeyboardPopup.setHeight(View.MeasureSpec.makeMeasureSpec(setEmojiKeyboardHeight(), View.MeasureSpec.EXACTLY));
            emojiKeyboardPopup.setWidth(View.MeasureSpec.makeMeasureSpec(getDisplayDimensions(context).x, View.MeasureSpec.EXACTLY));
            emojiKeyboardPopup.setAnimationStyle(0);
        }
    
        public void dismissEmojiKeyboard() {
            if (isShowed()) {
                emojiKeyboardPopup.dismiss();
            }
        }
    
        public boolean isShowed() {
            return emojiKeyboardPopup != null && emojiKeyboardPopup.isShowing();
        }
    
        /*
        * Emoji set up size
        * */
        public void resizeEmoji() {
            if (isShowed()) {
                WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
                WindowManager.LayoutParams layoutParams = (WindowManager.LayoutParams) emojiKeyboardPopup.getContentView().getLayoutParams();
                layoutParams.height = setEmojiKeyboardHeight();
                wm.updateViewLayout(emojiKeyboardPopup.getContentView(), layoutParams);
            }
        }
    
        public int setEmojiKeyboardHeight() {
            return emojiKbHeight == -1 && emojiKbHeight != screenHeight && emojiKbHeight < 80
                    ? (getDisplayDimensions(context).y / 2)
                    : emojiKbHeight;
        }
    
        public Point getDisplayDimensions(Context context) {
            Point size = new Point();
            WindowManager w = ((Activity) context).getWindowManager();
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) {
                w.getDefaultDisplay().getSize(size);
            } else {
                Display d = w.getDefaultDisplay();
                size.x = d.getWidth();
                size.y = d.getHeight();
            }
            return size;
        }
    }
    

    【讨论】:

      【解决方案4】:

      使用 lib github https://github.com/rockerhieu/emojicon

      public class EmojiKeyboard {
      
          private static final String TAG = "EmojiKeyboard";
          private static final String PREF_KEY_HEIGHT_KB = "EmojiKbHeight";
      
          private Context context;
          private int screenHeight = -1;
          private int emojiKbHeight = -1;
          private PopupWindow emojiKeyboardPopup;
          private View view;
          private SharedPreferences preferences;
      
          public EmojiKeyboard(Context context, View view) {
              if (context instanceof Activity) {
                  this.context = context;
                  this.view = view;
                  preferences = context.getSharedPreferences(context.getString(R.string.app_name), Context.MODE_PRIVATE);
      
                  //Restore EmojiKeyboard Height
                  emojiKbHeight = preferences.getInt(PREF_KEY_HEIGHT_KB, -1);
      
                  //TODO support less then 11 API, and not perfect resizing when switched the keyboard
                  view.addOnLayoutChangeListener(new View.OnLayoutChangeListener() {
                      @Override
                      public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) {
                          /*
                          * Get root view height
                          * */
                          screenHeight = screenHeight == -1 && bottom > oldBottom
                                  ? bottom
                                  : screenHeight;
      
                          /*
                          * Calculate soft keyboard height
                          * */
                          int dHeight = oldBottom - bottom;
                          boolean validHeight = emojiKbHeight == -1 && dHeight > 80 && bottom != oldBottom;
      
                          /*
                          * Сheck twice because the keyboard may have been switched
                          * */
                          emojiKbHeight = validHeight
                                  ? dHeight : emojiKbHeight != (dHeight) && dHeight > 0
                                  ? dHeight
                                  : emojiKbHeight;
      
                          /*
                          * Store emoji keyboard height into SharedPreferences
                          * */
                          preferences.edit().putInt(PREF_KEY_HEIGHT_KB, emojiKbHeight).commit();
      
                          /*
                          * If layout returned to a standard height then dismissing keyboard (OnBackPressed)
                          * */
                          if (screenHeight == bottom) {
                              dismissEmojiKeyboard();
                          }
      
                          /*
                          * Resize emoji on the go when a user switches between keyboards
                          * */
                          resizeEmoji();
                      }
                  });
              }
          }
      
      
          public void showEmoji() {
              if (emojiKeyboardPopup == null) {
                  createEmojiKeyboard();
              }
              if (!isShowed()) {
                  new Handler().postDelayed(new Runnable() {
                      public void run() {
                          emojiKeyboardPopup.showAtLocation(view, Gravity.BOTTOM, 0, 0);
                          resizeEmoji();
                      }
                  }, 10L);
      
              } else {
                  dismissEmojiKeyboard();
              }
          }
      
          public void createEmojiKeyboard() {
              EmojiView emojiKeyboard = new EmojiView(context, EmojiView.EMOJI_DARK_STYLE, new EmojiView.onEmojiClickListener() {
                  public void onBackspace() {
                      if (((Activity) context).getWindow().getCurrentFocus() instanceof EditText) {
                          ((Activity) context).getWindow().getCurrentFocus().dispatchKeyEvent(new KeyEvent(0, 67));
                      }
                  }
      
                  public void onEmojiSelected(Emojicon emojicon) {
                      if (((Activity) context).getWindow().getCurrentFocus() instanceof EditText) {
                          EmojiView.input((EditText) ((Activity) context).getWindow().getCurrentFocus(), emojicon);
                      }
                  }
              });
              emojiKeyboardPopup = new PopupWindow(emojiKeyboard);
              emojiKeyboardPopup.setHeight(View.MeasureSpec.makeMeasureSpec(setEmojiKeyboardHeight(), View.MeasureSpec.EXACTLY));
              emojiKeyboardPopup.setWidth(View.MeasureSpec.makeMeasureSpec(getDisplayDimensions(context).x, View.MeasureSpec.EXACTLY));
              emojiKeyboardPopup.setAnimationStyle(0);
          }
      
          public void dismissEmojiKeyboard() {
              if (isShowed()) {
                  emojiKeyboardPopup.dismiss();
              }
          }
      
          public boolean isShowed() {
              return emojiKeyboardPopup != null && emojiKeyboardPopup.isShowing();
          }
      
          /*
          * Emoji set up size
          * */
          public void resizeEmoji() {
              if (isShowed()) {
                  WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
                  WindowManager.LayoutParams layoutParams = (WindowManager.LayoutParams) emojiKeyboardPopup.getContentView().getLayoutParams();
                  layoutParams.height = setEmojiKeyboardHeight();
                  wm.updateViewLayout(emojiKeyboardPopup.getContentView(), layoutParams);
              }
          }
      
          public int setEmojiKeyboardHeight() {
              return emojiKbHeight == -1 && emojiKbHeight != screenHeight && emojiKbHeight < 80
                      ? (getDisplayDimensions(context).y / 2)
                      : emojiKbHeight;
          }
      
          public Point getDisplayDimensions(Context context) {
              Point size = new Point();
              WindowManager w = ((Activity) context).getWindowManager();
              if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) {
                  w.getDefaultDisplay().getSize(size);
              } else {
                  Display d = w.getDefaultDisplay();
                  size.x = d.getWidth();
                  size.y = d.getHeight();
              }
              return size;
          }
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2014-04-06
        • 1970-01-01
        • 1970-01-01
        • 2014-09-05
        • 2014-04-20
        • 1970-01-01
        • 2020-06-07
        • 1970-01-01
        相关资源
        最近更新 更多