{"id":35059,"date":"2024-11-26T10:11:46","date_gmt":"2024-11-26T02:11:46","guid":{"rendered":"https:\/\/fwq.ai\/blog\/35059\/"},"modified":"2024-11-26T10:11:46","modified_gmt":"2024-11-26T02:11:46","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:\/\/fwq.ai\/blog\/35059\/","title":{"rendered":"Android \u8f6f\u4ef6\u95ea\u9000\uff1a\u4e3a\u4ec0\u4e48 findViewById \u51fd\u6570\u8c03\u7528\u5931\u8d25\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173059634426519.jpg\" class=\"aligncenter\" title=\"Android \u8f6f\u4ef6\u95ea\u9000\uff1a\u4e3a\u4ec0\u4e48 findViewById \u51fd\u6570\u8c03\u7528\u5931\u8d25\uff1f\u63d2\u56fe\" alt=\"Android \u8f6f\u4ef6\u95ea\u9000\uff1a\u4e3a\u4ec0\u4e48 findViewById \u51fd\u6570\u8c03\u7528\u5931\u8d25\uff1f\u63d2\u56fe\" \/><\/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\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> \u767b\u5f55\u540e\u590d\u5236 <\/p>\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> \u767b\u5f55\u540e\u590d\u5236 <\/p>\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<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\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> \u767b\u5f55\u540e\u590d\u5236 <\/p>\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>\u4ee5\u4e0a\u5c31\u662fAndroid \u8f6f\u4ef6\u95ea\u9000\uff1a\u4e3a\u4ec0\u4e48 findViewById \u51fd\u6570\u8c03\u7528\u5931\u8d25\uff1f\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>android \u8f6f\u4ef6\u95ea\u9000\u89e3\u6790 \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 \u95ee\u9898\u8be6\u60c5 \u4e00\u6bb5 android \u4ee3\u7801\u5728\u4e0a\u95ea\u9000\uff0c\u5982\u4e0b\u6240\u793a\uff1a public class mainactivity extends appcompatactivity { webview webview = findviewbyid(r.id.webview); &#8230; } \u767b\u5f55\u540e\u590d\u5236 \u5f00\u53d1\u8005\u8be2\u95ee\u4ee3\u7801\u4e2d\u53ef\u80fd\u7684\u95ee\u9898\u6240\u5728\u3002 \u89e3\u51b3\u65b9\u6848 \u95ee\u9898\u51fa\u5728\u4ee5\u4e0b\u4ee3\u7801\u884c\uff1a webview webview = findviewbyid(r.id.webview); \u767b\u5f55\u540e\u590d\u5236 \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 \u8981\u89e3\u51b3\u6b64\u95ee\u9898\uff0c\u8bf7\u6309\u4ee5\u4e0b\u6b65\u9aa4\u64cd\u4f5c\uff1a \u5c06 webview \u58f0\u660e\u4e3a\u7c7b\u7684\u6210\u5458\u53d8\u91cf\uff1a public class mainactivity extends appcompatactivity { webview webview; &#8230; } \u767b\u5f55\u540e\u590d\u5236 \u5728 oncreate \u65b9\u6cd5\u4e2d\u521d\u59cb\u5316 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-35059","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/35059","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=35059"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/35059\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=35059"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=35059"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=35059"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}