{"id":1262,"date":"2023-03-18T09:52:35","date_gmt":"2023-03-18T01:52:35","guid":{"rendered":"https:\/\/www.appblog.cn\/?p=1262"},"modified":"2023-04-29T09:26:11","modified_gmt":"2023-04-29T01:26:11","slug":"android-scrollview-cannot-scroll-when-the-edittext-soft-keyboard-pops-up-in-full-screen","status":"publish","type":"post","link":"https:\/\/www.appblog.cn\/index.php\/2023\/03\/18\/android-scrollview-cannot-scroll-when-the-edittext-soft-keyboard-pops-up-in-full-screen\/","title":{"rendered":"Android\u5728\u5168\u5c4f\u4e0bScrollView\u5305\u88f9EditText\u8f6f\u952e\u76d8\u5f39\u51fa\u540e\uff0cScrollView\u65e0\u6cd5\u6eda\u52a8"},"content":{"rendered":"<h2>\u95ee\u9898\u63cf\u8ff0<\/h2>\n<p>\u5728\u5168\u5c4f\u4e0bScrollView\u5305\u88f9EditText\u8f6f\u952e\u76d8\u5f39\u51fa\u540e\uff0cScrollView\u65e0\u6cd5\u6eda\u52a8\uff0c\u8bbe\u7f6eadjustResize\u65e0\u6548<\/p>\n<h2>\u89e3\u51b3\u65b9\u6cd5<\/h2>\n<p>\u53c2\u8003\uff1a<a target=\"_blank\" rel=\"noopener\" href=\"https:\/\/stackoverflow.com\/questions\/21092888\/windowsoftinputmode-adjustresize-not-working-with-translucent-action-navbar\">https:\/\/stackoverflow.com\/questions\/21092888\/windowsoftinputmode-adjustresize-not-working-with-translucent-action-navbar<\/a><\/p>\n<p><!-- more --><\/p>\n<p>\u5728Activity\u7684\u6839\u5e03\u5c40\u4e0a\u8bbe\u7f6e\u5c5e\u6027\uff1a<\/p>\n<pre><code class=\"language-xml\">android:windowSoftInputMode=&quot;stateVisible|adjustResize&quot;\nandroid:fitsSystemWindows=&quot;true&quot;<\/code><\/pre>\n<p>adjustResize\u5c31\u53ef\u4ee5\u6210\u529f\u7684\u8d77\u4f5c\u7528\uff0c\u4f46\u4ee5\u4e0a\u505a\u6cd5\u4f1a\u5bfc\u81f4Toolbar\u5411\u4e0b\u5e73\u79fb\u4e86statusBar\u7684\u9ad8\u5ea6\uff0c\u6240\u4ee5\u5fc5\u987b\u91cd\u5199\u6839\u5e03\u5c40Layout<\/p>\n<p>\u89e3\u51b3\u529e\u6cd5\uff1a<\/p>\n<p>\uff081\uff09\u81ea\u5b9a\u4e49FullScreenLinearLayout<\/p>\n<pre><code class=\"language-java\">public class FullScreenLinearLayout extends LinearLayout {\n    private int[] mInsets = new int[4];\n\n    public FullScreenLinearLayout(@NonNull Context context) {\n        super(context);\n    }\n\n    public FullScreenLinearLayout(@NonNull Context context, @Nullable AttributeSet attrs) {\n        super(context, attrs);\n    }\n\n    public FullScreenLinearLayout(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {\n        super(context, attrs, defStyleAttr);\n    }\n\n    public final int[] getInsets() {\n        return mInsets;\n    }\n\n    @Override\n    protected final boolean fitSystemWindows(Rect insets) {\n        if (Build.VERSION.SDK_INT &gt;= Build.VERSION_CODES.KITKAT) {\n            \/\/ Intentionally do not modify the bottom inset. For some reason,\n            \/\/ if the bottom inset is modified, window resizing stops working.\n            \/\/ TODO: Figure out why.\n\n            mInsets[0] = insets.left;\n            mInsets[1] = insets.top;\n            mInsets[2] = insets.right;\n\n            insets.left = 0;\n            insets.top = 0;\n            insets.right = 0;\n        }\n\n        return super.fitSystemWindows(insets);\n    }\n\n    \/*\n    @Override\n    public final WindowInsets onApplyWindowInsets(WindowInsets insets) {\n        if (Build.VERSION.SDK_INT &gt;= Build.VERSION_CODES.KITKAT_WATCH) {\n            mInsets[0] = insets.getSystemWindowInsetLeft();\n            mInsets[1] = insets.getSystemWindowInsetTop();\n            mInsets[2] = insets.getSystemWindowInsetRight();\n            return super.onApplyWindowInsets(insets.replaceSystemWindowInsets(0, 0, 0,\n                    insets.getSystemWindowInsetBottom()));\n        } else {\n            return insets;\n        }\n    }\n    *\/\n}<\/code><\/pre>\n<p>\uff082\uff09\u6839\u5e03\u5c40FullScreenLinearLayout\u8bbe\u7f6e\u5c5e\u6027<\/p>\n<pre><code class=\"language-xml\">&lt;me.yezhou.lib.ui_widget.layout.FullScreenLinearLayout xmlns:android=&quot;http:\/\/schemas.android.com\/apk\/res\/android&quot;\n    android:layout_width=&quot;match_parent&quot;\n    android:layout_height=&quot;match_parent&quot;\n    android:orientation=&quot;vertical&quot;\n    android:fitsSystemWindows=&quot;true&quot;\n    &gt;<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u95ee\u9898\u63cf\u8ff0 \u5728\u5168\u5c4f\u4e0bScrollView\u5305\u88f9EditText\u8f6f\u952e\u76d8\u5f39\u51fa\u540e\uff0cScrollView\u65e0\u6cd5\u6eda\u52a8\uff0c\u8bbe\u7f6ead [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[119],"tags":[123],"class_list":["post-1262","post","type-post","status-publish","format-standard","hentry","category-android-ui","tag-scrollview"],"_links":{"self":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/1262","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/comments?post=1262"}],"version-history":[{"count":0,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/1262\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/media?parent=1262"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/categories?post=1262"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/tags?post=1262"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}