{"id":697,"date":"2023-02-26T15:02:50","date_gmt":"2023-02-26T07:02:50","guid":{"rendered":"https:\/\/www.appblog.cn\/?p=697"},"modified":"2023-04-29T17:50:40","modified_gmt":"2023-04-29T09:50:40","slug":"android-cannot-resolve-symbol-keyeventcompat-android-support-v4-view-keyeventcompat-not-found","status":"publish","type":"post","link":"https:\/\/www.appblog.cn\/index.php\/2023\/02\/26\/android-cannot-resolve-symbol-keyeventcompat-android-support-v4-view-keyeventcompat-not-found\/","title":{"rendered":"Android Cannot resolve symbol KeyEventCompat\uff08android.support.v4.view.KeyEventCompat\u627e\u4e0d\u5230\uff09"},"content":{"rendered":"<p>\u5347\u7ea7\u540ecompileSdkVersion\u4e3a26\uff0c\u56e0\u4e3a\u6b64\u65f6<code>classpath &#039;com.android.tools.build:gradle:3.0.0&#039;<\/code>\uff0cv4\u5305\u7684\u7248\u672c\u662f<code>27.0.0<\/code>\u3002 \u62a5KeyEventCompat\u7c7b\uff08\u9879\u76ee\u4e2d\u7528\u5230KeyEventCompat\u7684hasNoModifiers\u7b49\u65b9\u6cd5\u6765\u505a\u7684ViewPager\u7684\u61d2\u52a0\u8f7d\uff09\u627e\u4e0d\u5230\uff0c\u56de\u770b<code>25.3.1<\/code>\u7248\u7684v4\u5305\u4e2d\u6b64\u7c7b\u662f\u5b58\u5728\u7684\uff0c\u7ecf\u786e\u8ba4KeyEventCompat\u7c7b\u5728<code>27.0.0<\/code>\u7248\u672c\u4e2d\u662f\u4e0d\u5b58\u5728\u7684\uff0c\u6700\u540e\u67e5\u770b\u6e90\u7801\u624d\u77e5\u9053hasNoModifiers\u65b9\u6cd5\u5df2\u7ecf\u88abKeyEvent\u5b9e\u73b0\u4e86\u3002 <\/p>\n<p><!-- more --><\/p>\n<p>\u8d34\u51fa\u89e3\u51b3\u6b64\u5904\u4fee\u6539\u7684\u7528\u4e8e\u5b9e\u73b0ViewPager\u61d2\u52a0\u8f7d\u65b9\u6cd5\u7684\u90e8\u5206\u4ee3\u7801<\/p>\n<pre><code class=\"language-java\">public boolean executeKeyEvent(KeyEvent event) {\n    boolean handled = false;\n    if (event.getAction() == KeyEvent.ACTION_DOWN) {\n        switch (event.getKeyCode()) {\n        case KeyEvent.KEYCODE_DPAD_LEFT:\n            handled = arrowScroll(FOCUS_LEFT);\n            break;\n        case KeyEvent.KEYCODE_DPAD_RIGHT:\n            handled = arrowScroll(FOCUS_RIGHT);\n            break;\n        case KeyEvent.KEYCODE_TAB:\n            if (Build.VERSION.SDK_INT &gt;= 11) {\n\/\/\u62a5\u9519\u5730\u65b9\n                \/\/ The focus finder had a bug handling FOCUS_FORWARD and FOCUS_BACKWARD\n                \/\/ before Android 3.0. Ignore the tab key on those devices.\n\/\/              if (KeyEventCompat.hasNoModifiers(event)) {\n\/\/                  handled = arrowScroll(FOCUS_FORWARD);\n\/\/              } else if (KeyEventCompat.hasModifiers(event, KeyEvent.META_SHIFT_ON)) {\n\/\/                  handled = arrowScroll(FOCUS_BACKWARD);\n\/\/              }\n\n\/\/\u6b63\u786e\u4ee3\u7801\n                if (event.hasNoModifiers()) {\n                    handled = arrowScroll(FOCUS_FORWARD);\n                } else if (event.hasModifiers(KeyEvent.META_SHIFT_ON)) {\n                    handled = arrowScroll(FOCUS_BACKWARD);\n                }\n            }\n            break;\n        }\n    }\n    return handled;\n}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u5347\u7ea7\u540ecompileSdkVersion\u4e3a26\uff0c\u56e0\u4e3a\u6b64\u65f6classpath &#039;com.android [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[61],"tags":[201],"class_list":["post-697","post","type-post","status-publish","format-standard","hentry","category-android-basic","tag-support-v4"],"_links":{"self":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/697","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=697"}],"version-history":[{"count":0,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/697\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/media?parent=697"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/categories?post=697"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/tags?post=697"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}