{"id":203327,"date":"2025-05-22T12:10:40","date_gmt":"2025-05-22T04:10:40","guid":{"rendered":"https:\/\/server.hk\/cnblog\/203327\/"},"modified":"2025-05-22T12:10:40","modified_gmt":"2025-05-22T04:10:40","slug":"android-%e8%bd%af%e4%bb%b6%e9%97%aa%e9%80%80%ef%bc%9a%e4%b8%ba%e4%bb%80%e4%b9%88-findviewbyid-%e5%87%bd%e6%95%b0%e8%b0%83%e7%94%a8%e5%a4%b1%e8%b4%a5%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/203327\/","title":{"rendered":"Android \u8f6f\u4ef6\u95ea\u9000\uff1a\u4e3a\u4ec0\u4e48 findViewById \u51fd\u6570\u8c03\u7528\u5931\u8d25\uff1f"},"content":{"rendered":"<p><b><\/b>     <\/p>\n<h1>Android \u8f6f\u4ef6\u95ea\u9000\uff1a\u4e3a\u4ec0\u4e48 findViewById \u51fd\u6570\u8c03\u7528\u5931\u8d25\uff1f<\/h1>\n<p>\u5927\u5bb6\u597d\uff0c\u4eca\u5929\u672c\u4eba\u7ed9\u5927\u5bb6\u5e26\u6765\u6587\u7ae0<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u300aAndroid \u8f6f\u4ef6\u95ea\u9000\uff1a\u4e3a\u4ec0\u4e48 findViewById \u51fd\u6570\u8c03\u7528\u5931\u8d25\uff1f\u300b<\/span>\uff0c\u6587\u4e2d\u5185\u5bb9\u4e3b\u8981\u6d89\u53ca\u5230<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><\/span><\/span>\uff0c\u5982\u679c\u4f60\u5bf9<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u6587\u7ae0<\/span>\u65b9\u9762\u7684\u77e5\u8bc6\u70b9\u611f\u5174\u8da3\uff0c\u90a3\u5c31\u8bf7\u5404\u4f4d\u670b\u53cb\u7ee7\u7eed\u770b\u4e0b\u53bb\u5427~\u5e0c\u671b\u80fd\u771f\u6b63\u5e2e\u5230\u4f60\u4eec\uff0c\u8c22\u8c22\uff01<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241105\/1730771147672978cbcd69a.jpg\" class=\"aligncenter\"><\/p>\n<p><strong>android \u8f6f\u4ef6\u95ea\u9000\u89e3\u6790<\/strong><\/p>\n<p>\u521d\u5b66\u8005\u5728 android \u5f00\u53d1\u4e2d\u7ecf\u5e38\u4f1a\u9047\u5230\u8f6f\u4ef6\u95ea\u9000\u95ee\u9898\u3002\u672c\u6587\u5c06\u8ba8\u8bba\u8fd9\u4e2a\u95ee\u9898\u5e76\u63d0\u4f9b\u8be6\u7ec6\u7684\u89e3\u51b3\u65b9\u6848\u3002<\/p>\n<p><strong>\u95ee\u9898\u8be6\u60c5<\/strong><\/p>\n<p>\u4e00\u6bb5 android \u4ee3\u7801\u5728\u6a21\u62df\u5668\u4e0a\u95ea\u9000\uff0c\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n<pre>public class mainactivity extends appcompatactivity {\n    webview webview = findviewbyid(r.id.webview);\n    ...\n}<\/pre>\n<p>\u5f00\u53d1\u8005\u8be2\u95ee\u4ee3\u7801\u4e2d\u53ef\u80fd\u7684\u95ee\u9898\u6240\u5728\u3002<\/p>\n<p><strong>\u89e3\u51b3\u65b9\u6848<\/strong><\/p>\n<p>\u95ee\u9898\u51fa\u5728\u4ee5\u4e0b\u4ee3\u7801\u884c\uff1a<\/p>\n<pre>webview webview = findviewbyid(r.id.webview);<\/pre>\n<p>\u5728\u8c03\u7528 findviewbyid \u51fd\u6570\u4e4b\u524d\uff0c\u672a\u5c06 webview \u58f0\u660e\u4e3a\u7c7b\u7684\u6210\u5458\u53d8\u91cf\u3002\u8fd9\u5bfc\u81f4\u7f16\u8bd1\u5668\u5c1d\u8bd5\u5728 oncreate \u65b9\u6cd5\u4e4b\u5916\u5f15\u7528\u4e00\u4e2a\u672a\u521d\u59cb\u5316\u7684\u53d8\u91cf\uff0c\u4ece\u800c\u4ea7\u751f\u95ea\u9000\u3002<\/p>\n<p>\u8981\u89e3\u51b3\u6b64\u95ee\u9898\uff0c\u8bf7\u6309\u4ee5\u4e0b\u6b65\u9aa4\u64cd\u4f5c\uff1a<\/p>\n<ol>\n<li>\u5c06 webview \u58f0\u660e\u4e3a\u7c7b\u7684\u6210\u5458\u53d8\u91cf\uff1a<\/li>\n<\/ol>\n<pre>public class mainactivity extends appcompatactivity {\n    webview webview;\n    ...\n}<\/pre>\n<ol>\n<li>\u5728 oncreate \u65b9\u6cd5\u4e2d\u521d\u59cb\u5316 webview\uff1a<\/li>\n<\/ol>\n<pre>@Override\nprotected void onCreate(Bundle savedInstanceState) {\n    super.onCreate(savedInstanceState);\n    setContentView(R.layout.activity_main);\n    webView = findViewById(R.id.WebView);\n    ...\n}<\/pre>\n<p>\u8fd9\u6837\u505a\u5c06\u786e\u4fdd\u5728\u5f15\u7528 webview \u53d8\u91cf\u4e4b\u524d\u5bf9\u5176\u8fdb\u884c\u6b63\u786e\u521d\u59cb\u5316\u3002<\/p>\n<p>\u7ec8\u4e8e\u4ecb\u7ecd\u5b8c\u5566\uff01\u5c0f\u4f19\u4f34\u4eec\uff0c\u8fd9\u7bc7\u5173\u4e8e\u300aAndroid \u8f6f\u4ef6\u95ea\u9000\uff1a\u4e3a\u4ec0\u4e48 findViewById \u51fd\u6570\u8c03\u7528\u5931\u8d25\uff1f\u300b\u7684\u4ecb\u7ecd\u5e94\u8be5\u8ba9\u4f60\u6536\u83b7\u591a\u591a\u4e86\u5427\uff01\u6b22\u8fce\u5927\u5bb6\u6536\u85cf\u6216\u5206\u4eab\u7ed9\u66f4\u591a\u9700\u8981\u5b66\u4e60\u7684\u670b\u53cb\u5427~\u516c\u4f17\u53f7\u4e5f\u4f1a\u53d1\u5e03\u6587\u7ae0\u76f8\u5173\u77e5\u8bc6\uff0c\u5feb\u6765\u5173\u6ce8\u5427\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Android \u8f6f\u4ef6\u95ea\u9000\uff1a\u4e3a\u4ec0\u4e48&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4925],"tags":[],"class_list":["post-203327","post","type-post","status-publish","format-standard","hentry","category-4925"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/203327","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=203327"}],"version-history":[{"count":0,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/203327\/revisions"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=203327"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=203327"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=203327"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}