{"id":37,"date":"2024-04-10T13:20:42","date_gmt":"2024-04-10T05:20:42","guid":{"rendered":"https:\/\/www.loml.cc\/?p=37"},"modified":"2024-04-10T21:36:43","modified_gmt":"2024-04-10T13:36:43","slug":"android-%e8%a1%a8%e6%83%85%e9%9d%a2%e6%9d%bf%e4%b8%8e%e9%94%ae%e7%9b%98%e5%88%87%e6%8d%a2%e9%97%aa%e7%83%81%e8%a7%a3%e5%86%b3%e6%96%b9%e6%b3%95","status":"publish","type":"post","link":"https:\/\/www.loml.cc\/index.php\/2024\/04\/10\/android-%e8%a1%a8%e6%83%85%e9%9d%a2%e6%9d%bf%e4%b8%8e%e9%94%ae%e7%9b%98%e5%88%87%e6%8d%a2%e9%97%aa%e7%83%81%e8%a7%a3%e5%86%b3%e6%96%b9%e6%b3%95\/","title":{"rendered":"Android \u8868\u60c5\u9762\u677f\u4e0e\u952e\u76d8\u5207\u6362\u95ea\u70c1\u89e3\u51b3\u65b9\u6cd5"},"content":{"rendered":"\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p class=\"wp-block-paragraph\"><\/p>\n<cite><strong>\u5229\u7528\u4e00\u4e2a\u540d\u4e3aEmotionKeyboard\u7684\u5de5\u5177\u7c7b\uff0c\u5728Android\u5e94\u7528\u4e2d\u89e3\u51b3\u8868\u60c5\u9762\u677f\u4e0e\u8f6f\u952e\u76d8\u5207\u6362\u95ea\u70c1\u7684\u95ee\u9898\u3002\u8be5\u5de5\u5177\u7c7b\u57fa\u4e8e\u8f93\u5165\u6846\u7684\u7126\u70b9\u72b6\u6001\u548c\u89e6\u6478\u4e8b\u4ef6\uff0c\u5b9e\u73b0\u4e86\u5728\u8f93\u5165\u6846\u7684\u4e0a\u65b9\u663e\u793a\u8868\u60c5\u9762\u677f\uff0c\u540c\u65f6\u5728\u9700\u8981\u65f6\u9690\u85cf\u8f6f\u952e\u76d8\u7684\u529f\u80fd\u3002\u901a\u8fc7\u8be5\u5de5\u5177\u7c7b\uff0c\u7528\u6237\u53ef\u4ee5\u65b9\u4fbf\u5730\u5728\u81ea\u5df1\u7684\u5e94\u7528\u4e2d\u96c6\u6210\u8868\u60c5\u9762\u677f\u4e0e\u8f6f\u952e\u76d8\u7684\u5207\u6362\u529f\u80fd\uff0c\u4ece\u800c\u63d0\u5347\u7528\u6237\u7684\u4ea4\u4e92\u4f53\u9a8c\u3002<\/strong><\/cite><\/blockquote>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u5e03\u5c40\u4ee3\u7801<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;?xml version=\"1.0\" encoding=\"utf-8\"?&gt;\n&lt;androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android=\"http:\/\/schemas.android.com\/apk\/res\/android\"\n    xmlns:app=\"http:\/\/schemas.android.com\/apk\/res-auto\"\n    android:id=\"@+id\/chat_activity_root\"\n    android:layout_width=\"match_parent\"\n    android:layout_height=\"match_parent\"\n    android:clickable=\"true\"&gt;\n\n    &lt;LinearLayout\n        android:id=\"@+id\/relativeLayout\"\n        android:layout_width=\"match_parent\"\n        android:layout_height=\"match_parent\"\n        android:orientation=\"vertical\"&gt;\n\n        &lt;!-- \u9876\u90e8\u680f --&gt;\n\n        &lt;LinearLayout\n            android:id=\"@+id\/top_bar\"\n            android:layout_width=\"match_parent\"\n            android:layout_height=\"50dp\"\n            android:background=\"@color\/FAFAFA\"\n            android:gravity=\"center_vertical\"\n            android:orientation=\"horizontal\"&gt;\n\n            &lt;ImageView\n                android:id=\"@+id\/go_back\"\n                android:layout_width=\"wrap_content\"\n                android:layout_height=\"wrap_content\"\n                android:layout_marginStart=\"20dp\"\n                android:src=\"@drawable\/go_back_icon\" \/&gt;\n\n            &lt;TextView\n                android:id=\"@+id\/user_name\"\n                android:layout_width=\"0dp\"\n                android:layout_height=\"wrap_content\"\n                android:layout_weight=\"1\"\n                android:gravity=\"center\"\n                android:text=\"\u7528\u6237\u540d\"\n                android:textColor=\"@android:color\/black\"\n                android:textSize=\"18sp\" \/&gt;\n\n            &lt;ImageView\n                android:id=\"@+id\/menu_more\"\n                android:layout_width=\"wrap_content\"\n                android:layout_height=\"wrap_content\"\n                android:layout_marginEnd=\"20dp\"\n                android:src=\"@drawable\/more_menu_icon\" \/&gt;\n\n        &lt;\/LinearLayout&gt;\n\n\n            &lt;!-- \u804a\u5929\u5185\u5bb9\u5e03\u5c40 --&gt;\n        &lt;FrameLayout\n            android:id=\"@+id\/chat_frame\"\n            android:layout_width=\"match_parent\"\n            android:layout_height=\"0dp\"\n            android:layout_weight=\"1\"\n            android:layout_marginTop=\"0dp\"\n            android:layout_marginBottom=\"0dp\"&gt;\n                &lt;!-- \u5728\u8fd9\u91cc\u653e\u7f6e\u4f60\u7684\u804a\u5929\u5185\u5bb9 --&gt;\n        &lt;\/FrameLayout&gt;\n\n\n        &lt;!-- \u5e95\u90e8\u83dc\u5355\u680f --&gt;\n        &lt;LinearLayout\n            android:id=\"@+id\/bottom_bar\"\n            android:layout_width=\"match_parent\"\n            android:layout_height=\"wrap_content\"\n            android:background=\"@color\/FAFAFA\"\n            android:minHeight=\"55dp\"\n            android:orientation=\"horizontal\"\n            android:paddingTop=\"10dp\"&gt; \n\n            &lt;!-- \u8bed\u97f3 --&gt;\n            &lt;ImageView\n                android:id=\"@+id\/bt_voice\"\n                android:layout_width=\"wrap_content\"\n                android:layout_height=\"wrap_content\"\n                android:layout_gravity=\"bottom\"\n                android:layout_marginStart=\"10dp\"\n                android:layout_marginBottom=\"10dp\"\n                android:src=\"@drawable\/voice_icon\" \/&gt;\n\n            &lt;!-- \u8f93\u5165\u6846 --&gt;\n            &lt;EditText\n                android:id=\"@+id\/chat_box\"\n                android:layout_width=\"0dp\"\n                android:layout_height=\"wrap_content\"\n                android:layout_gravity=\"bottom\"\n                android:layout_marginLeft=\"10dp\"\n                android:layout_marginTop=\"10dp\"\n                android:layout_marginRight=\"10dp\"\n                android:layout_weight=\"1\"\n                android:background=\"@drawable\/input_box\"\n                android:ems=\"10\"\n                android:inputType=\"text|textMultiLine\"\n                android:maxLines=\"5\"\n                android:paddingLeft=\"16dp\"\n                android:paddingTop=\"8dp\"\n                android:paddingRight=\"16dp\"\n                android:paddingBottom=\"8dp\"\n                android:text=\"\" \/&gt;\n\n\n            &lt;!-- \u8868\u60c5 --&gt;\n            &lt;ImageView\n                android:id=\"@+id\/bt_emoji\"\n                android:layout_width=\"wrap_content\"\n                android:layout_height=\"wrap_content\"\n                android:layout_gravity=\"bottom\"\n                android:layout_marginEnd=\"5dp\"\n                android:layout_marginBottom=\"10dp\"\n                android:src=\"@drawable\/emoji_icon\" \/&gt;\n\n            &lt;!-- \u83dc\u5355 --&gt;\n            &lt;ImageView\n                android:id=\"@+id\/bt_menu\"\n                android:layout_width=\"wrap_content\"\n                android:layout_height=\"wrap_content\"\n                android:layout_gravity=\"bottom\"\n                android:layout_marginEnd=\"5dp\"\n                android:layout_marginBottom=\"10dp\"\n                android:src=\"@drawable\/menu_add_icon\"\n                android:visibility=\"visible\" \/&gt;\n            &lt;!-- \u83dc\u5355 --&gt;\n\n            &lt;!--\u53d1\u9001--&gt;\n            &lt;LinearLayout\n                android:layout_width=\"wrap_content\"\n                android:layout_height=\"wrap_content\"\n                android:layout_gravity=\"bottom\"\n                android:layout_marginEnd=\"10dp\"\n                android:layout_marginBottom=\"10dp\"\n                android:orientation=\"horizontal\"&gt;\n\n                &lt;android.widget.Button\n                    android:id=\"@+id\/send\"\n                    android:layout_width=\"65dp\"\n                    android:layout_height=\"35dp\"\n                    android:layout_gravity=\"center\"\n                    android:background=\"@drawable\/button_background\"\n                    android:gravity=\"center\"\n                    android:text=\"@string\/send\"\n                    android:textColor=\"@color\/white\"\n                    android:visibility=\"gone\" \/&gt;\n            &lt;\/LinearLayout&gt;\n\n\n        &lt;\/LinearLayout&gt;\n\n\n        &lt;androidx.viewpager2.widget.ViewPager2\n            android:id=\"@+id\/menu_paper\"\n            android:layout_width=\"match_parent\"\n            android:layout_height=\"wrap_content\"\n            android:visibility=\"gone\" \/&gt;\n\n        &lt;androidx.viewpager2.widget.ViewPager2\n            android:id=\"@+id\/emoji_paper\"\n            android:layout_width=\"match_parent\"\n            android:layout_height=\"wrap_content\"\n            android:visibility=\"gone\" \/&gt;\n\n    &lt;\/LinearLayout&gt;\n\n&lt;\/androidx.coordinatorlayout.widget.CoordinatorLayout&gt;\n<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u5b9e\u73b0\u8868\u60c5\u9762\u677f\u4e0e\u8f6f\u952e\u76d8\u4e4b\u95f4\u5207\u6362\u7684EmotionKeyboard\u7c7b<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>import android.app.Activity;\nimport android.content.Context;\nimport android.content.SharedPreferences;\nimport android.graphics.Rect;\nimport android.util.DisplayMetrics;\nimport android.view.MotionEvent;\nimport android.view.View;\nimport android.view.ViewGroup;\nimport android.view.WindowManager;\nimport android.view.inputmethod.InputMethodManager;\nimport android.widget.EditText;\nimport android.widget.LinearLayout;\n\n\/**\n * EmotionKeyboard\u662f\u4e00\u4e2a\u7ba1\u7406\u8868\u60c5\u952e\u76d8\u7684\u5de5\u5177\u7c7b\n * \u6e90\u7801\u6765\u81ea\u5f00\u6e90\u9879\u76eehttps:\/\/github.com\/dss886\/Android-EmotionInputDetector\n * \u672c\u4eba\u4ec5\u505a\u7ec6\u5fae\u4fee\u6539\u4ee5\u53ca\u4ee3\u7801\u89e3\u6790\n *\/\npublic class EmotionKeyboard {\n    \n    private static final String SHARE_PREFERENCE_NAME = \"EmotionKeyboard\"; \/\/ \u5b58\u50a8\u8868\u60c5\u952e\u76d8\u76f8\u5173\u4fe1\u606f\u7684SharedPreferences\u540d\u79f0\n    private static final String SHARE_PREFERENCE_SOFT_INPUT_HEIGHT = \"soft_input_height\"; \/\/ \u8f6f\u952e\u76d8\u9ad8\u5ea6\u5728SharedPreferences\u4e2d\u7684key\n    private Activity mActivity; \/\/ \u5f53\u524dActivity\n    private InputMethodManager mInputManager; \/\/ \u8f6f\u952e\u76d8\u7ba1\u7406\u7c7b\n    private SharedPreferences sp; \/\/ SharedPreferences\u5bf9\u8c61\uff0c\u7528\u4e8e\u5b58\u50a8\u8f6f\u952e\u76d8\u9ad8\u5ea6\u7b49\u4fe1\u606f\n    private View mEmotionLayout,mMenuLayout; \/\/ \u8868\u60c5\u5e03\u5c40,\u83dc\u5355\u5e03\u5c40\n    private View emotionButton,menuButton; \/\/ \u8868\u8868\u60c5\u6309\u94ae,\u83dc\u5355\u6309\u94ae\n    \n    private EditText mEditText; \/\/ \u7f16\u8f91\u6846\n    private View mContentView; \/\/ \u5185\u5bb9\u5e03\u5c40\uff0c\u7528\u4e8e\u56fa\u5b9abar\u7684\u9ad8\u5ea6\uff0c\u9632\u6b62\u8df3\u95ea\n    \n    \/\/ \u6784\u9020\u51fd\u6570\u79c1\u6709\u5316\uff0c\u53ea\u80fd\u901a\u8fc7with\u65b9\u6cd5\u83b7\u53d6\u5b9e\u4f8b\n    private EmotionKeyboard() {\n    }\n    \n    \/**\n     * \u5916\u90e8\u9759\u6001\u8c03\u7528\uff0c\u7528\u4e8e\u83b7\u53d6EmotionKeyboard\u5b9e\u4f8b\n     *\n     * @param activity \u5f53\u524dActivity\n     * @return EmotionKeyboard\u5b9e\u4f8b\n     *\/\n    public static EmotionKeyboard with(Activity activity) {\n        EmotionKeyboard emotionInputDetector = new EmotionKeyboard();\n        emotionInputDetector.mActivity = activity;\n        emotionInputDetector.mInputManager = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);\n        emotionInputDetector.sp = activity.getSharedPreferences(SHARE_PREFERENCE_NAME, Context.MODE_PRIVATE);\n        return emotionInputDetector;\n    }\n    \n    \/**\n     * \u7ed1\u5b9a\u5185\u5bb9view\uff0c\u6b64view\u7528\u4e8e\u56fa\u5b9abar\u7684\u9ad8\u5ea6\uff0c\u9632\u6b62\u8df3\u95ea\n     *\n     * @param contentView \u5185\u5bb9view\n     * @return \u5f53\u524dEmotionKeyboard\u5b9e\u4f8b\n     *\/\n    public EmotionKeyboard bindToContent(View contentView) {\n        mContentView = contentView;\n        return this;\n    }\n    \n    \/**\n     * \u7ed1\u5b9a\u7f16\u8f91\u6846\n     *\n     * @param editText \u7f16\u8f91\u6846\n     * @return \u5f53\u524dEmotionKeyboard\u5b9e\u4f8b\n     *\/\n    public EmotionKeyboard bindToEditText(EditText editText) {\n        mEditText = editText;\n        mEditText.requestFocus();\n        mEditText.setOnTouchListener((v, event) -> {\n            if (event.getAction() == MotionEvent.ACTION_UP &amp;&amp; mEmotionLayout.isShown()) {\n                lockContentHeight(); \/\/ \u663e\u793a\u8f6f\u952e\u76d8\u65f6\uff0c\u9501\u5b9a\u5185\u5bb9\u9ad8\u5ea6\uff0c\u9632\u6b62\u8df3\u95ea\u3002\n                hideEmotionLayout(true); \/\/ \u9690\u85cf\u8868\u60c5\u5e03\u5c40\uff0c\u663e\u793a\u8f6f\u952e\u76d8\n                \/\/ \u8f6f\u952e\u76d8\u663e\u793a\u540e\uff0c\u91ca\u653e\u5185\u5bb9\u9ad8\u5ea6\n                mEditText.postDelayed(() -> unlockContentHeightDelayed(), 200L);\n            }\n            \n            if (event.getAction() == MotionEvent.ACTION_UP &amp;&amp; mMenuLayout.isShown()) {\n                menuButton.animate().rotationBy(-45f).setDuration(250).start();\n                lockContentHeight(); \/\/ \u663e\u793a\u8f6f\u952e\u76d8\u65f6\uff0c\u9501\u5b9a\u5185\u5bb9\u9ad8\u5ea6\uff0c\u9632\u6b62\u8df3\u95ea\u3002\n                hideMenuLayout(true); \/\/ \u9690\u85cf\u83dc\u5355\u5e03\u5c40\uff0c\u663e\u793a\u8f6f\u952e\u76d8\n                \/\/ \u8f6f\u952e\u76d8\u663e\u793a\u540e\uff0c\u91ca\u653e\u5185\u5bb9\u9ad8\u5ea6\n                mEditText.postDelayed(() -> unlockContentHeightDelayed(), 200L);\n            }\n            return false;\n        });\n        return this;\n    }\n    \n    \/**\n     * \u7ed1\u5b9a\u8868\u60c5\u6309\u94ae\n     *\n     * @return \u5f53\u524dEmotionKeyboard\u5b9e\u4f8b\n     *\/\n    public EmotionKeyboard bindToEmojiButton() {\n        emotionButton.setOnClickListener(v -> {\n            \n            \/\/\u5982\u679c\u70b9\u51fb\u8868\u60c5\u6309\u94ae\u65f6\u6b63\u5728\u663e\u793a\u83dc\u5355\u5e03\u5c40\n            if (mMenuLayout.isShown()){\n                menuButton.animate().rotationBy(-45f).setDuration(250).start();\n                lockContentHeight(); \/\/ \u663e\u793a\u8f6f\u952e\u76d8\u65f6\uff0c\u9501\u5b9a\u5185\u5bb9\u9ad8\u5ea6\uff0c\u9632\u6b62\u8df3\u95ea\u3002\n                hideMenuLayout(false); \/\/ \u9690\u85cf\u8868\u60c5\u5e03\u5c40\uff0c\u4f46\u4e0d\u663e\u793a\u8f6f\u952e\u76d8\n                showEmotionLayout();  \/\/ \u663e\u793a\u8868\u60c5\u5e03\u5c40\n                unlockContentHeightDelayed(); \/\/ \u8868\u60c5\u5e03\u5c40\u663e\u793a\u540e\uff0c\u91ca\u653e\u5185\u5bb9\u9ad8\u5ea6\n            }\n            \/\/\u5982\u679c\u5df2\u7ecf\u663e\u793a\u8868\u60c5\u5e03\u5c40\uff0c\u518d\u6b21\u70b9\u51fb\u5219\u5207\u6362\u952e\u76d8\n            else if (mEmotionLayout.isShown()) {\n                lockContentHeight(); \/\/ \u663e\u793a\u8f6f\u952e\u76d8\u65f6\uff0c\u9501\u5b9a\u5185\u5bb9\u9ad8\u5ea6\uff0c\u9632\u6b62\u8df3\u95ea\u3002\n                hideEmotionLayout(true); \/\/ \u9690\u85cf\u8868\u60c5\u5e03\u5c40\uff0c\u663e\u793a\u8f6f\u952e\u76d8\n                unlockContentHeightDelayed(); \/\/ \u8f6f\u952e\u76d8\u663e\u793a\u540e\uff0c\u91ca\u653e\u5185\u5bb9\u9ad8\u5ea6\n            } else {\n                \/\/\u5982\u679c\u6b63\u5728\u663e\u793a\u952e\u76d8\uff0c\u5219\u9690\u85cf\u952e\u76d8\u663e\u793a\u8868\u60c5\u5e03\u5c40\n                if (isSoftInputShown()) { \/\/ \u540c\u4e0a\n                    lockContentHeight();\n                    showEmotionLayout();\n                    unlockContentHeightDelayed();\n                } else {\n                    \/\/\u5982\u679c\u90fd\u6ca1\u6709\u663e\u793a\uff0c\u5219\u76f4\u63a5\u663e\u793a\u8868\u60c5\u5e03\u5c40\n                    \n                    showEmotionLayout(); \/\/ \u4e24\u8005\u90fd\u6ca1\u663e\u793a\uff0c\u76f4\u63a5\u663e\u793a\u8868\u60c5\u5e03\u5c40\n                }\n            }\n        });\n        return this;\n    }\n    \n    \/**\n     * \u7ed1\u5b9a\u83dc\u5355\u6309\u94ae\n     *\n     * @return \u5f53\u524dEmotionKeyboard\u5b9e\u4f8b\n     *\/\n    public EmotionKeyboard bindToMenuButton() {\n        menuButton.setOnClickListener(v -> {\n            \n            \/\/\u5982\u679c\u70b9\u51fb\u83dc\u5355\u6309\u94ae\u65f6\u6b63\u5728\u663e\u793a\u8868\u60c5\u5e03\u5c40\n            if (mEmotionLayout.isShown()){\n                \/\/\u65cb\u8f6c45\u00b0\u5ef6\u8fdf250\u6beb\u79d2\n                menuButton.animate().rotationBy(45f).setDuration(250).start();\n                lockContentHeight(); \/\/ \u663e\u793a\u8868\u60c5\u9762\u677f\u65f6\uff0c\u9501\u5b9a\u5185\u5bb9\u9ad8\u5ea6\uff0c\u9632\u6b62\u8df3\u95ea\u3002\n                hideEmotionLayout(false);   \/\/ \u9690\u85cf\u8868\u60c5\u5e03\u5c40\uff0c\u4f46\u4e0d\u663e\u793a\u8f6f\u952e\u76d8\n                showMenuLayout();   \/\/\u663e\u793a\u83dc\u5355\u5e03\u5c40\n                unlockContentHeightDelayed(); \/\/ \u83dc\u5355\u5e03\u5c40\u663e\u793a\u540e\uff0c\u91ca\u653e\u5185\u5bb9\u9ad8\u5ea6\n            }\n            \/\/\u5982\u679c\u5df2\u7ecf\u663e\u793a\u83dc\u5355\u5e03\u5c40\uff0c\u518d\u6b21\u70b9\u51fb\u5219\u5207\u6362\u952e\u76d8\n            else if (mMenuLayout.isShown()) {\n                menuButton.animate().rotationBy(-45f).setDuration(250).start();\n                \n                lockContentHeight(); \/\/ \u663e\u793a\u8f6f\u952e\u76d8\u65f6\uff0c\u9501\u5b9a\u5185\u5bb9\u9ad8\u5ea6\uff0c\u9632\u6b62\u8df3\u95ea\u3002\n                hideMenuLayout(true); \/\/ \u9690\u85cf\u83dc\u5355\u5e03\u5c40\uff0c\u663e\u793a\u8f6f\u952e\u76d8\n                unlockContentHeightDelayed(); \/\/ \u8f6f\u952e\u76d8\u663e\u793a\u540e\uff0c\u91ca\u653e\u5185\u5bb9\u9ad8\u5ea6\n            } else {\n                \/\/\u5982\u679c\u6b63\u5728\u663e\u793a\u952e\u76d8\n                if (isSoftInputShown()) { \/\/ \u540c\u4e0a\n                    menuButton.animate().rotationBy(45f).setDuration(250).start();\n                    lockContentHeight();\n                    showMenuLayout();\n                    unlockContentHeightDelayed();\n                } else {\n                    menuButton.animate().rotationBy(45f).setDuration(250).start();\n                    \/\/\u5982\u679c\u6ca1\u6709\u663e\u793a\u952e\u76d8\u4e5f\u6ca1\u6709\u663e\u793a\u8868\u60c5\n                    showMenuLayout(); \/\/ \u4e24\u8005\u90fd\u6ca1\u663e\u793a\uff0c\u76f4\u63a5\u663e\u793a\u83dc\u5355\u5e03\u5c40\n                }\n            }\n        });\n        return this;\n    }\n    \/**\n     * \u8bbe\u7f6e\u6309\u94ae\u952e\n     *\n     * @param emotionView \u8868\u60c5\u5185\u5bb9\u5e03\u5c40\n     * @return \u5f53\u524dEmotionKeyboard\u5b9e\u4f8b\n     *\/\n    public EmotionKeyboard setButtonView(View emotionView,View menuView) {\n        emotionButton = emotionView;\n        menuButton = menuView;\n        return this;\n    }\n    \n    \/**\n     * \u8bbe\u7f6e\u8868\u60c5\u5185\u5bb9\u5e03\u5c40\n     *\n     * @param emotionView \u8868\u60c5\u5185\u5bb9\u5e03\u5c40\n     * @return \u5f53\u524dEmotionKeyboard\u5b9e\u4f8b\n     *\/\n    public EmotionKeyboard setEmotionView(View emotionView) {\n        mEmotionLayout = emotionView;\n        return this;\n    }\n    \n    \/**\n     * \u8bbe\u7f6e\u83dc\u5355\u5185\u5bb9\u5e03\u5c40\n     *\n     * @param menuView \u83dc\u5355\u5185\u5bb9\u5e03\u5c40\n     * @return \u5f53\u524dEmotionKeyboard\u5b9e\u4f8b\n     *\/\n    public EmotionKeyboard setMenuView(View menuView) {\n        mMenuLayout = menuView;\n        return this;\n    }\n    \/**\n     * \u6784\u5efaEmotionKeyboard\u5b9e\u4f8b\n     *\n     * @return \u5f53\u524dEmotionKeyboard\u5b9e\u4f8b\n     *\/\n    public EmotionKeyboard build() {\n        \/\/ \u8bbe\u7f6e\u8f6f\u952e\u76d8\u7684\u6a21\u5f0f\uff1aSOFT_INPUT_ADJUST_RESIZE \u8868\u793aActivity\u7684\u4e3b\u7a97\u53e3\u603b\u662f\u4f1a\u88ab\u8c03\u6574\u5927\u5c0f\uff0c\u4ece\u800c\u4fdd\u8bc1\u8f6f\u952e\u76d8\u663e\u793a\u7a7a\u95f4\u3002\n        \/\/ \u4ece\u800c\u65b9\u4fbf\u8ba1\u7b97\u8f6f\u952e\u76d8\u7684\u9ad8\u5ea6\n        mActivity.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN |\n                WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);\n        \/\/ \u9690\u85cf\u8f6f\u952e\u76d8\n        hideSoftInput();\n        return this;\n    }\n    \n    \/**\n     * \u70b9\u51fb\u8fd4\u56de\u952e\u65f6\u5148\u9690\u85cf\u8868\u60c5\/\u83dc\u5355\u5e03\u5c40\n     *\n     * @return \u662f\u5426\u62e6\u622a\u8fd4\u56de\u4e8b\u4ef6\n     *\/\n    public boolean interceptBackPress() {\n        if (mEmotionLayout.isShown()) {\n            hideEmotionLayout(false);\n            return true;\n        } else if (mMenuLayout.isShown()) {\n            hideMenuLayout(false);\n            return true;\n        }\n        return false;\n    }\n    \n    \/**\n     * \u663e\u793a\u8868\u60c5\u5e03\u5c40\n     *\/\n    private void showEmotionLayout() {\n        int softInputHeight = getSupportSoftInputHeight();\n        \/\/ \u5982\u679c\u83b7\u53d6\u8f6f\u952e\u76d8\u9ad8\u5ea6\u5931\u8d25\uff0c\u5219\u4f7f\u7528\u9ed8\u8ba4\u503c 400\n        if (softInputHeight == 0) {\n            softInputHeight = sp.getInt(SHARE_PREFERENCE_SOFT_INPUT_HEIGHT, 765);\n        }\n        LogUtils.d(\"\u8868\u60c5\u5e03\u5c40\u9ad8\u5ea6\uff1a\"+softInputHeight);\n        \/\/ \u9690\u85cf\u8f6f\u952e\u76d8\n        hideSoftInput();\n        \/\/ \u5c06\u8f6f\u952e\u76d8\u9ad8\u5ea6\u8bbe\u7f6e\u7ed9\u8868\u60c5\u5e03\u5c40\n        mEmotionLayout.getLayoutParams().height = softInputHeight;\n        LogUtils.d(\"\u5c06\u8f6f\u952e\u76d8\u9ad8\u5ea6\u8bbe\u7f6e\u7ed9\u8868\u60c5\u5e03\u5c40\"+String.valueOf(softInputHeight));\n        mEmotionLayout.setVisibility(View.VISIBLE);\n    }\n    \/**\n     * \u663e\u793a\u83dc\u5355\u5e03\u5c40\n     *\/\n    private void showMenuLayout() {\n        int softInputHeight = getSupportSoftInputHeight();\n        \/\/ \u5982\u679c\u83b7\u53d6\u8f6f\u952e\u76d8\u9ad8\u5ea6\u5931\u8d25\uff0c\u5219\u4f7f\u7528\u9ed8\u8ba4\u503c 400\n        if (softInputHeight == 0) {\n            softInputHeight = sp.getInt(SHARE_PREFERENCE_SOFT_INPUT_HEIGHT, 765);\n        }\n        LogUtils.d(\"\u83dc\u5355\u5e03\u5c40\u9ad8\u5ea6\uff1a\"+softInputHeight);\n        \/\/ \u9690\u85cf\u8f6f\u952e\u76d8\n        hideSoftInput();\n        \/\/ \u5c06\u8f6f\u952e\u76d8\u9ad8\u5ea6\u8bbe\u7f6e\u7ed9\u8868\u60c5\u5e03\u5c40\n        mMenuLayout.getLayoutParams().height = softInputHeight;\n        LogUtils.d(\"\u5c06\u8f6f\u952e\u76d8\u9ad8\u5ea6\u8bbe\u7f6e\u7ed9\u8868\u60c5\u5e03\u5c40\"+String.valueOf(softInputHeight));\n        mMenuLayout.setVisibility(View.VISIBLE);\n    }\n    \n    \/**\n     * \u9690\u85cf\u8868\u60c5\u5e03\u5c40\n     *\n     * @param showSoftInput \u662f\u5426\u663e\u793a\u8f6f\u952e\u76d8\n     *\/\n    private void hideEmotionLayout(boolean showSoftInput) {\n        if (mEmotionLayout.isShown()) {\n            mEmotionLayout.setVisibility(View.GONE);\n            if (showSoftInput) {\n                showSoftInput();\n            }\n        }\n    }\n    \/**\n     * \u9690\u85cf\u83dc\u5355\u5e03\u5c40\n     *\n     * @param showSoftInput \u662f\u5426\u663e\u793a\u8f6f\u952e\u76d8\n     *\/\n    private void hideMenuLayout(boolean showSoftInput) {\n        if (mMenuLayout.isShown()) {\n            mMenuLayout.setVisibility(View.GONE);\n            if (showSoftInput) {\n                showSoftInput();\n            }\n        }\n    }\n    \/**\n     * \u9501\u5b9a\u5185\u5bb9\u9ad8\u5ea6\uff0c\u9632\u6b62\u8df3\u95ea\n     *\/\n    private void lockContentHeight() {\n        LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) mContentView.getLayoutParams();\n        params.height = mContentView.getHeight();\n        LogUtils.d(\"\u5185\u5bb9\u9ad8\u5ea6\"+ params.height);\n        \n        params.weight = 0.0F;\n    }\n    \n    \/**\n     * \u91ca\u653e\u88ab\u9501\u5b9a\u7684\u5185\u5bb9\u9ad8\u5ea6\n     *\/\n    private void unlockContentHeightDelayed() {\n        mEditText.postDelayed(new Runnable() {\n            @Override\n            public void run() {\n                ((LinearLayout.LayoutParams) mContentView.getLayoutParams()).weight = 1.0F;\n            }\n        }, 200L);\n    }\n    \n    \/**\n     * \u7f16\u8f91\u6846\u83b7\u53d6\u7126\u70b9\uff0c\u5e76\u663e\u793a\u8f6f\u952e\u76d8\n     *\/\n    private void showSoftInput() {\n        mEditText.requestFocus();\n        mEditText.post(new Runnable() {\n            @Override\n            public void run() {\n                mInputManager.showSoftInput(mEditText, 0);\n            }\n        });\n    }\n    \n    \/**\n     * \u9690\u85cf\u8f6f\u952e\u76d8\n     *\/\n    private void hideSoftInput() {\n        mInputManager.hideSoftInputFromWindow(mEditText.getWindowToken(), 0);\n    }\n    \n    \/**\n     * \u662f\u5426\u663e\u793a\u8f6f\u952e\u76d8\n     *\n     * @return \u662f\u5426\u663e\u793a\u8f6f\u952e\u76d8\n     *\/\n    private boolean isSoftInputShown() {\n        return getSupportSoftInputHeight() != 0;\n    }\n    \n    \/**\n     * \u83b7\u53d6\u8f6f\u952e\u76d8\u7684\u9ad8\u5ea6\n     *\n     * @return \u8f6f\u952e\u76d8\u9ad8\u5ea6\n     *\/\n    private int getSupportSoftInputHeight() {\n\n        \n        Rect r = new Rect();\n        mActivity.getWindow().getDecorView().getWindowVisibleDisplayFrame(r);\n        int screenHeight = mActivity.getWindow().getDecorView().getRootView().getHeight();\n        int softInputHeight = screenHeight - r.bottom;\n        if (isNavigationBarExist()){\n            softInputHeight = softInputHeight - getSoftButtonsBarHeight();\n        }\n        LogUtils.d(\"\u8f6f\u952e\u76d8\u9ad8\u5ea6\"+ (softInputHeight));\n        \n        if (softInputHeight &lt;= 0) {\n            LogUtils.w(\"EmotionKeyboard--Warning: value of softInputHeight is below zero!\");\n        }\n        if (softInputHeight > 200) {\n            sp.edit().putInt(SHARE_PREFERENCE_SOFT_INPUT_HEIGHT, softInputHeight).apply();\n        }\n        \n        return softInputHeight;\n    }\n    \n    \/**\n     * \u83b7\u53d6\u5e95\u90e8\u865a\u62df\u6309\u952e\u680f\u7684\u9ad8\u5ea6\n     *\n     * @return \u865a\u62df\u6309\u952e\u680f\u9ad8\u5ea6\n     *\/\n    private int getSoftButtonsBarHeight() {\n        DisplayMetrics metrics = new DisplayMetrics();\n        mActivity.getWindowManager().getDefaultDisplay().getMetrics(metrics);\n        int usableHeight = metrics.heightPixels;\n        mActivity.getWindowManager().getDefaultDisplay().getRealMetrics(metrics);\n        int realHeight = metrics.heightPixels;\n        LogUtils.d(\"\u865a\u62df\u6309\u952e\u680f\u9ad8\u5ea6\"+ (realHeight - usableHeight));\n        if (realHeight > usableHeight) {\n            return realHeight - usableHeight;\n        } else {\n            return 0;\n        }\n    }\n    \n    \/**\n     * \u83b7\u53d6\u8f6f\u952e\u76d8\u9ad8\u5ea6\n     *\n     * @return \u8f6f\u952e\u76d8\u9ad8\u5ea6\n     *\/\n    public int getKeyBoardHeight() {\n        return sp.getInt(SHARE_PREFERENCE_SOFT_INPUT_HEIGHT, 850);\n    }\n    \n    private static final String NAVIGATION= \"navigationBarBackground\";\n        \/**\n     * \u68c0\u67e5\u8bbe\u5907\u662f\u5426\u5177\u6709\u5bfc\u822a\u680f\uff08\u865a\u62df\u6216\u7269\u7406\uff09\u3002\n     *\n     * @return \u5982\u679c\u5b58\u5728\u5bfc\u822a\u680f\u5219\u8fd4\u56de true\uff0c\u5426\u5219\u8fd4\u56de false\n     *\/\n    public boolean isNavigationBarExist() {\n        \/\/ \u83b7\u53d6\u7a97\u53e3\u88c5\u9970\u89c6\u56fe\u7684\u6839\u89c6\u56fe\n        ViewGroup vp = (ViewGroup) mActivity.getWindow().getDecorView();\n        \n        \/\/ \u904d\u5386\u88c5\u9970\u89c6\u56fe\u7684\u6240\u6709\u5b50\u89c6\u56fe\n        if (vp != null) {\n            for (int i = 0; i &lt; vp.getChildCount(); i++) {\n                \/\/ \u83b7\u53d6\u5b50\u89c6\u56fe\u7684\u4e0a\u4e0b\u6587\n                vp.getChildAt(i).getContext().getPackageName();\n                \n                \/\/ \u68c0\u67e5\u5b50\u89c6\u56fe\u662f\u5426\u5177\u6709\u5bfc\u822a\u680f\n                if (vp.getChildAt(i).getId() != View.NO_ID &amp;&amp; NAVIGATION.equals(mActivity.getResources().getResourceEntryName(vp.getChildAt(i).getId()))) {\n                    return true;\n                }\n            }\n        }\n        return false;\n    }\n    \n    \n    \n}<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u4f7f\u7528\u65b9\u6cd5<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>        \/\/ \u4f7f\u7528EmotionKeyboard.with()\u65b9\u6cd5\u83b7\u53d6EmotionKeyboard\u7684\u5b9e\u4f8b\uff0c\u5e76\u8fdb\u884c\u7ed1\u5b9a\u64cd\u4f5c\n        EmotionKeyboard.with(this)\n                .bindToEditText(chatBox) \/\/ \u7ed1\u5b9a\u7f16\u8f91\u6846\n                .setButtonView(btEmoji,btMenu)\/\/\u8bbe\u7f6e\u6309\u94ae\n                .bindToEmojiButton() \/\/ \u7ed1\u5b9a\u8868\u60c5\u6309\u94ae\n                .setEmotionView(emojiPaper) \/\/ \u8bbe\u7f6e\u8868\u60c5\u5e03\u5c40\n                .bindToMenuButton() \/\/ \u7ed1\u5b9a\u83dc\u5355\u6309\u94ae\n                .setMenuView(menuPaper) \/\/ \u8bbe\u7f6e\u83dc\u5355\u5e03\u5c40\n                .bindToContent(chatFrame) \/\/ \u7ed1\u5b9a\u5185\u5bb9\u5e03\u5c40\n                .build(); \/\/ \u6784\u5efaEmotionKeyboard\u5b9e\u4f8b<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u5229\u7528\u4e00\u4e2a\u540d\u4e3aEmotionKeyboard\u7684\u5de5\u5177\u7c7b\uff0c\u5728Android\u5e94\u7528\u4e2d\u89e3\u51b3\u8868\u60c5\u9762\u677f\u4e0e\u8f6f\u952e\u76d8\u5207\u6362\u95ea\u70c1\u7684\u95ee\u9898\u3002\u8be5\u5de5\u5177\u7c7b\u57fa\u4e8e\u8f93\u5165\u6846\u7684\u7126\u70b9\u72b6\u6001\u548c\u89e6\u6478\u4e8b\u4ef6\uff0c\u5b9e\u73b0\u4e86\u5728\u8f93\u5165\u6846\u7684\u4e0a\u65b9\u663e\u793a\u8868\u60c5\u9762\u677f\uff0c\u540c\u65f6\u5728\u9700\u8981\u65f6\u9690\u85cf\u8f6f\u952e\u76d8\u7684\u529f\u80fd\u3002\u901a\u8fc7\u8be5\u5de5\u5177\u7c7b\uff0c\u7528\u6237\u53ef\u4ee5\u65b9\u4fbf\u5730\u5728\u81ea\u5df1\u7684\u5e94\u7528\u4e2d\u96c6\u6210\u8868\u60c5\u9762\u677f\u4e0e\u8f6f\u952e\u76d8\u7684\u5207\u6362\u529f\u80fd\uff0c\u4ece\u800c\u63d0\u5347\u7528\u6237\u7684\u4ea4\u4e92\u4f53\u9a8c\u3002<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-37","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/www.loml.cc\/index.php\/wp-json\/wp\/v2\/posts\/37","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.loml.cc\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.loml.cc\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.loml.cc\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.loml.cc\/index.php\/wp-json\/wp\/v2\/comments?post=37"}],"version-history":[{"count":7,"href":"https:\/\/www.loml.cc\/index.php\/wp-json\/wp\/v2\/posts\/37\/revisions"}],"predecessor-version":[{"id":46,"href":"https:\/\/www.loml.cc\/index.php\/wp-json\/wp\/v2\/posts\/37\/revisions\/46"}],"wp:attachment":[{"href":"https:\/\/www.loml.cc\/index.php\/wp-json\/wp\/v2\/media?parent=37"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.loml.cc\/index.php\/wp-json\/wp\/v2\/categories?post=37"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.loml.cc\/index.php\/wp-json\/wp\/v2\/tags?post=37"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}