{"id":34619,"date":"2024-11-26T09:25:55","date_gmt":"2024-11-26T01:25:55","guid":{"rendered":"https:\/\/fwq.ai\/blog\/34619\/"},"modified":"2024-11-26T09:25:55","modified_gmt":"2024-11-26T01:25:55","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%e4%bb%a3%e7%a0%81%e5%9c%a8setcontentview%e4%b9%8b%e5%89%8d%e8%b0%83%e7%94%a8findviewbyid%e4%bc%9a%e5%af%bc%e8%87%b4","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/34619\/","title":{"rendered":"Android\u8f6f\u4ef6\u95ea\u9000\uff1a\u4e3a\u4ec0\u4e48\u4ee3\u7801\u5728setContentView()\u4e4b\u524d\u8c03\u7528findViewById()\u4f1a\u5bfc\u81f4\u95ea\u9000\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173054168187131.jpg\" class=\"aligncenter\" title=\"Android\u8f6f\u4ef6\u95ea\u9000\uff1a\u4e3a\u4ec0\u4e48\u4ee3\u7801\u5728setContentView()\u4e4b\u524d\u8c03\u7528findViewById()\u4f1a\u5bfc\u81f4\u95ea\u9000\uff1f\u63d2\u56fe\" alt=\"Android\u8f6f\u4ef6\u95ea\u9000\uff1a\u4e3a\u4ec0\u4e48\u4ee3\u7801\u5728setContentView()\u4e4b\u524d\u8c03\u7528findViewById()\u4f1a\u5bfc\u81f4\u95ea\u9000\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>android\u8f6f\u4ef6\u95ea\u9000<\/strong><\/p>\n<p>\u4e00\u4f4dandroid\u521d\u5b66\u8005\u5728\u4e0a\u8fd0\u884c\u4ee3\u7801\u65f6\u9047\u5230\u95ea\u9000\u95ee\u9898\uff0c\u4ee5\u4e0b\u662f\u4ed6\u63d0\u4f9b\u7684\u4ee3\u7801\uff1a<\/p>\n<pre>public class mainactivity extends appcompatactivity {\n    final webview webview = findviewbyid(r.id.webview);\n    \/\/ ...\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u95ee\u9898\uff1a<\/strong><\/p>\n<p>\u95ee\u9898\u51fa\u5728\u4ee3\u7801\u4e2d\u8fc7\u65e9\u8c03\u7528findviewbyid()\u51fd\u6570\u3002\u5728\u8c03\u7528setcontentview()\u8bbe\u7f6e\u5e03\u5c40\u4e4b\u524d\uff0cfindviewbyid()\u65e0\u6cd5\u627e\u5230\u4efb\u4f55\u89c6\u56fe\u3002<\/p>\n<p><strong>\u89e3\u51b3\u65b9\u6848\uff1a<\/strong><\/p>\n<p>\u5c06findviewbyid()\u8c03\u7528\u79fb\u52a8\u5230setcontentview()\u4e4b\u540e\uff0c\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n<pre>public class MainActivity extends AppCompatActivity {\n    WebView webView;\n    \/\/ ...\n\n    @Override\n    protected void onCreate(Bundle savedInstanceState) {\n        super.onCreate(savedInstanceState);\n        setContentView(R.layout.activity_main);\n        this.webView = findViewById(R.id.WebView);\n        \/\/ ...\n    }\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u73b0\u5728\uff0csetcontentview()\u5c06\u52a0\u8f7d\u5e03\u5c40\u5e76\u6e32\u67d3\u89c6\u56fe\uff0c\u7136\u540efindviewbyid()\u624d\u80fd\u6b63\u786e\u627e\u5230webview\u89c6\u56fe\u3002\u8fd9\u6837\u5c31\u53ef\u4ee5\u89e3\u51b3\u95ea\u9000\u95ee\u9898\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fAndroid\u8f6f\u4ef6\u95ea\u9000\uff1a\u4e3a\u4ec0\u4e48\u4ee3\u7801\u5728setContentView()\u4e4b\u524d\u8c03\u7528findViewById()\u4f1a\u5bfc\u81f4\u95ea\u9000\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 \u4e00\u4f4dandroid\u521d\u5b66\u8005\u5728\u4e0a\u8fd0\u884c\u4ee3\u7801\u65f6\u9047\u5230\u95ea\u9000\u95ee\u9898\uff0c\u4ee5\u4e0b\u662f\u4ed6\u63d0\u4f9b\u7684\u4ee3\u7801\uff1a public class mainactivity extends appcompatactivity { final webview webview = findviewbyid(r.id.webview); \/\/ &#8230; } \u767b\u5f55\u540e\u590d\u5236 \u95ee\u9898\uff1a \u95ee\u9898\u51fa\u5728\u4ee3\u7801\u4e2d\u8fc7\u65e9\u8c03\u7528findviewbyid()\u51fd\u6570\u3002\u5728\u8c03\u7528setcontentview()\u8bbe\u7f6e\u5e03\u5c40\u4e4b\u524d\uff0cfindviewbyid()\u65e0\u6cd5\u627e\u5230\u4efb\u4f55\u89c6\u56fe\u3002 \u89e3\u51b3\u65b9\u6848\uff1a \u5c06findviewbyid()\u8c03\u7528\u79fb\u52a8\u5230setcontentview()\u4e4b\u540e\uff0c\u5982\u4e0b\u6240\u793a\uff1a public class MainActivity extends AppCompatActivity { WebView webView; \/\/ &#8230; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); this.webView = findViewById(R.id.WebView); \/\/ &#8230; } } \u767b\u5f55\u540e\u590d\u5236 \u73b0\u5728\uff0csetcontentview()\u5c06\u52a0\u8f7d\u5e03\u5c40\u5e76\u6e32\u67d3\u89c6\u56fe\uff0c\u7136\u540efindviewbyid()\u624d\u80fd\u6b63\u786e\u627e\u5230webview\u89c6\u56fe\u3002\u8fd9\u6837\u5c31\u53ef\u4ee5\u89e3\u51b3\u95ea\u9000\u95ee\u9898\u3002 \u4ee5\u4e0a\u5c31\u662fAndroid\u8f6f\u4ef6\u95ea\u9000\uff1a\u4e3a\u4ec0\u4e48\u4ee3\u7801\u5728setContentView()\u4e4b\u524d\u8c03\u7528findViewById()\u4f1a\u5bfc\u81f4\u95ea\u9000\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},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-34619","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/34619","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=34619"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/34619\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=34619"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=34619"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=34619"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}