{"id":14707,"date":"2023-11-29T11:06:59","date_gmt":"2023-11-29T03:06:59","guid":{"rendered":"https:\/\/www.zhidianwl.com\/zhidian\/?p=14707"},"modified":"2023-11-29T11:06:59","modified_gmt":"2023-11-29T03:06:59","slug":"java%e5%bc%80%e5%8f%91%e4%b8%80%e4%b8%aa%e7%ae%80%e5%8d%95%e7%9a%84%e5%ae%89%e5%8d%93app%e6%80%8e%e4%b9%88%e5%81%9a%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/www.zhidianwl.com\/zhidian\/2023\/14707\/","title":{"rendered":"java\u5f00\u53d1\u4e00\u4e2a\u7b80\u5355\u7684\u5b89\u5353app\u600e\u4e48\u505a\uff1f"},"content":{"rendered":"<p>\u5728\u8fd9\u7bc7\u6587\u7ae0\u4e2d\uff0c\u6211\u4eec\u5c06\u5b66\u4e60\u5982\u4f55\u4f7f\u7528Java\u5f00\u53d1\u4e00\u4e2a\u7b80\u5355\u7684\u5b89\u5353app\u3002\u5728\u5f00\u59cb\u4e4b\u524d\uff0c\u8bf7\u786e\u4fdd\u4f60\u5df2\u7ecf\u5b89\u88c5\u4e86Android Studio\uff0c\u8fd9\u662fGoogle\u5b98\u65b9\u652f\u6301\u7684\u5b89\u5353\u5e94\u7528\u5f00\u53d1\u8f6f\u4ef6\u3002\u4f60\u53ef\u4ee5\u4ece\u8fd9\u91cc\u4e0b\u8f7d\uff1ahttps:\/\/developer.android.com\/studio\/<\/p>\n<p>\u4e00\u3001\u521b\u5efa\u65b0\u9879\u76ee\uff1a<\/p>\n<p>1. \u6253\u5f00Android Studio\uff0c\u70b9\u51fb\u201cStart a new Android Studio project\u201d\u3002<\/p>\n<p>2. \u9009\u62e9\u4e00\u4e2a\u6a21\u677f\uff0c\u5bf9\u4e8e\u521d\u5b66\u8005\uff0c\u53ef\u4ee5\u9009\u62e9\u201cEmpty Activity\u201d\uff0c\u7136\u540e\u70b9\u51fb\u201cNext\u201d\u3002<\/p>\n<p>3. \u4e3a\u4f60\u7684\u9879\u76ee\u8f93\u5165\u540d\u79f0\u3001\u5305\u540d\uff08\u7c7b\u4f3c\u4e8e\u57df\u540d\uff0c\u4f46\u53cd\u7740\u5199\uff0c\u4f8b\u5982\uff1acom.example.myapp\uff09\uff0c\u7136\u540e\u9009\u62e9\u4f60\u7684\u9879\u76ee\u4fdd\u5b58\u4f4d\u7f6e\uff0c\u70b9\u51fb\u201cFinish\u201d\u3002<\/p>\n<p>\u4e8c\u3001\u9879\u76ee\u7ed3\u6784\u4e0e\u7ec4\u6210\uff1a<\/p>\n<p>1. app\uff1a\u9879\u76ee\u7684\u4e3b\u6587\u4ef6\u5939\u3002<\/p>\n<p>   &#8211; build.gradle\uff1a\u7f16\u8bd1\u548c\u6784\u5efa\u8bbe\u7f6e\u3002<\/p>\n<p>   &#8211; src\uff1a\u9879\u76ee\u7684\u4e3b\u8981\u8d44\u6e90\u548c\u6e90<a href=\"https:\/\/www.anzhuoe.com\/\">\u5b89\u5353app\u5f00\u53d1\u5de5\u5177<\/a>\u4ee3\u7801\u3002<\/p>\n<p>2. manifests\uff1a\u5b89\u5353\u8bbe\u5907\u4e0a\u5e94\u7528\u7684\u914d\u7f6e\u6587\u4ef6\u3002<\/p>\n<p>   &#8211; AndroidManifest.xml\uff1a\u5b9a\u4e49\u5e94\u7528\u7684\u6743\u9650\uff0c\u7ec4\u4ef6\u548c\u5176\u4ed6\u5c5e\u6027\u3002<\/p>\n<p>3. java\uff1a\u5305\u542bJava\u7c7b\u548cViewModel\u3002<\/p>\n<p>   &#8211; MainActivity.java\uff1a\u5e94\u7528\u4e3b\u8981\u7684\u529f\u80fd\u4ee3\u7801\u3002<\/p>\n<p>4. res\uff1a\u5305\u542b\u6240\u6709\u53ef\u89c6\u5143\u7d20\u7684\u8d44\u6e90\u6587\u4ef6\u5939\u3002<\/p>\n<p>   &#8211; layout\uff1a\u754c\u9762\u6587\u4ef6\uff08XML\uff09\u3002<\/p>\n<p>     &#8211; activity_main.xml\uff1a\u4e3b\u754c\u9762\u5e03\u5c40\u6587\u4ef6\u3002<\/p>\n<p>   &#8211; drawable\uff1a\u56fe\u7247\u8d44\u6e90\u3002<\/p>\n<p>   &#8211; mipmap\uff1a\u542f\u52a8\u56fe\u6807\u3002<\/p>\n<p>   &#8211; values\uff1a\u9879\u76ee\u4e2d\u4f7f\u7528\u7684\u989c\u8272\u3001\u5c3a\u5bf8\u3001\u5b57\u4f53\u6837\u5f0f\u7b49\u3002<\/p>\n<p>     &#8211; colors.xml\uff1a\u989c\u8272\u503c\u3002<\/p>\n<p>     &#8211; strings.xml\uff1a\u5b57\u7b26\u4e32\u8d44\u6e90\u3002<\/p>\n<p>     &#8211; styles.xml\uff1a\u6587\u5b57\u6837\u5f0f\u3002<\/p>\n<p>\u4e09\u3001\u7f16\u5199\u4ee3\u7801\uff1a<\/p>\n<p>1. \u5728activity_main.xml\u4e2d\u5b9a\u4e49\u5e03\u5c40\uff1a<\/p>\n<p>activity_main.xml\u662f\u4e3b\u5c4f\u5e55\u7684\u5e03\u5c40\u6587\u4ef6\u3002\u8fd9\u91cc\uff0c\u6211\u4eec\u5c06\u521b\u5efa\u4e00\u4e2a\u7b80\u5355\u7684\u754c\u9762\uff0c\u5305\u62ec\u4e00\u4e2a\u6309\u94ae\u548c\u4e00\u4e2a\u6587\u672c\u6846\u3002<\/p>\n<p>\u6253\u5f00activity_main.xml\u6587\u4ef6\uff0c\u7c98\u8d34\u4ee5\u4e0b\u4ee3\u7801\uff1a<\/p>\n<p>&#8220;`xml<\/p>\n<\/p>\n<p>    xmlns:tools=&#8221;http:\/\/schemas.android.com\/tools&#8221;<\/p>\n<p>    android:layout_width=&#8221;match_parent&#8221;<\/p>\n<p>    android:layout_height=&#8221;match_parent&#8221;<\/p>\n<p>    android:padding=&#8221;10dp&#8221;<\/p>\n<p>    tools:context=&#8221;.MainActivity&#8221; &gt;<\/p>\n<\/p>\n<p>        android:id=&#8221;@+id\/btn_click&#8221;<\/p>\n<p>        android:layout_width=&#8221;wrap_content&#8221;<\/p>\n<p>        android:layout_height=&#8221;wrap_content&#8221;<\/p>\n<p>        android:layout_marginBottom=&#8221;20dp&#8221;<\/p>\n<p>        android:layout_centerInParent=&#8221;true&#8221;<\/p>\n<p>        android:text=&#8221;@string\/click_me&#8221; \/&gt;<\/p>\n<\/p>\n<p>        android:id=&#8221;@+id\/tv_text&#8221;<\/p>\n<p>        android:layout_width=&#8221;wrap_content&#8221;<\/p>\n<p>        android:layout_height=&#8221;wrap_content&#8221;<\/p>\n<p>        android:layout_below=&#8221;@id\/btn_click&#8221;<\/p>\n<p>        android:layout_centerInParent=&#8221;true&#8221;<\/p>\n<p>\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/i.cdn.yimenapp.com\/2023-04\/07\/10\/13048455093.jpg\" \/><\/figure>\n<\/p>\n<p>      android:text=&#8221;@string\/hello_world&#8221;<\/p>\n<p>        android:textSize=&#8221;22sp&#8221; \/&gt;<\/p>\n<p><p>&#8220;`<\/p>\n<p>\u4e3a\u4e86\u907f\u514d\u786c\u7f16\u7801\uff0c\u53ef\u4ee5\u5c06\u6309\u94ae\u548c\u6587\u672c\u6846\u7684\u6587\u672c\u653e\u5165strings.xml\u6587\u4ef6\u4e2d\u3002\u6253\u5f00values\/strings.xml\uff0c\u7136\u540e\u6dfb\u52a0\u8fd9\u4e24\u4e2a\u5b57\u7b26\u4e32\uff1a<\/p>\n<p>&#8220;`xml<\/p>\n<p>\n<p>    SimpleApp<\/p>\n<p>    Hello World!<\/p>\n<p>    Click Me!<\/p>\n<\/p>\n<p>&#8220;`<\/p>\n<p>2. \u4e3a\u6309\u94ae\u6dfb\u52a0\u70b9\u51fb\u4e8b\u4ef6\uff1a<\/p>\n<p>\u63a5\u4e0b\u6765\uff0c\u5728MainActivity.java\u6587\u4ef6\u4e2d\uff0c\u6211\u4eec\u5c06\u4e3a\u6309\u94ae\u6dfb\u52a0\u4e00\u4e2a\u70b9\u51fb\u4e8b\u4ef6\uff0c\u6539\u53d8TextView\u7684\u6587\u672c\u5185\u5bb9\u3002<\/p>\n<p>\u6253\u5f00MainActivity.java\u6587\u4ef6\uff0c\u7c98\u8d34\u4ee5\u4e0b\u4ee3\u7801\uff1a<\/p>\n<p>&#8220;`java<\/p>\n<p>package com.example.simpleapp;<\/p>\n<p>import androidx.appcompat.app.AppCompatActivity;<\/p>\n<p>import android.os.Bundle;<\/p>\n<p>import android.view.View;<\/p>\n<p>import android.widget.Button;<\/p>\n<p>import android.widget.TextView;<\/p>\n<p>public class MainActivity extends AppCompatActivity {<\/p>\n<p>    private Button btnClick;<\/p>\n<p>    private TextView tvText;<\/p>\n<p>    @Override<\/p>\n<p>    protected void onCreate(Bundle savedInstanceState) {<\/p>\n<p>        super.onCreate(savedInstanceState);<\/p>\n<p>        setContentView(R.layout.activity_main);<\/p>\n<p>        btnClick = findViewById(R.id.btn_click);<\/p>\n<p>        tvText = findViewById(R.id.tv_text);<\/p>\n<p>        btnClick.setOnClickListener(new View.OnClickListener() {<\/p>\n<p>            @Override<\/p>\n<p>            public void onClick(View view) {<a href=\"https:\/\/www.anzhuoe.com\/\">\u5b89\u5353app\u5236\u4f5c<\/a><\/p>\n<p>                tvText.setText(&#8220;You clicked the button!&#8221;);<\/p>\n<p>            }<\/p>\n<p>        });<\/p>\n<p>    }<\/p>\n<p>}<\/p>\n<p>&#8220;`<\/p>\n<p>\u73b0\u5728\uff0c\u4f60\u5df2\u7ecf\u521b\u5efa\u4e86\u4e00\u4e2a\u7b80\u5355\u7684\u5b89\u5353app\uff0c\u5f53\u4f60\u70b9\u51fb\u6309\u94ae\u65f6\uff0c\u6587\u672c\u6846\u4e2d\u7684\u6587\u672c\u5c06\u6539\u53d8\u3002<\/p>\n<p>\u56db\u3001\u8fd0\u884c\u548c\u6d4b\u8bd5\u5e94\u7528\uff1a<\/p>\n<p>\u5728Android Studio\u5de5\u5177\u680f\u4e2d\uff0c\u70b9\u51fb\u8fd0\u884c\u6309\u94ae\uff08\u7eff\u8272\u4e09\u89d2\u5f62\u56fe\u6807\uff09\uff0c\u9009\u62e9\u4e00\u4e2a\u5b89\u5353\u8bbe\u5907\u6216\u6a21\u62df\u5668\u6765\u8fd0\u884c\u4f60\u7684\u5e94\u7528\u3002\u4f60\u73b0\u5728\u53ef\u4ee5\u770b\u5230app\u8fd0\u884c\u5728\u8bbe\u5907\u4e0a\uff0c\u5f53\u4f60\u70b9\u51fb\u6309\u94ae\u65f6\uff0c\u6587\u672c\u6846\u7684\u6587\u672c\u5c06\u53d1\u751f\u53d8\u5316\u3002<\/p>\n<p>\u81f3\u6b64\uff0c\u6211\u4eec\u5df2\u7ecf\u5b66\u4e60\u4e86\u5982\u4f55\u5f00\u53d1\u4e00\u4e2a\u7b80\u5355\u7684\u5b89\u5353app\u3002\u73b0\u5728\u4f60\u53ef\u4ee5\u5c1d\u8bd5\u6dfb\u52a0\u66f4\u591a\u529f\u80fd\uff0c\u5982\u5b9e\u73b0\u7f51\u7edc\u8bf7\u6c42\u3001\u7ed8\u5236\u56fe\u8868\u7b49\u3002\u4e0d\u65ad\u5b66\u4e60\u548c\u5b9e\u8df5\uff0c\u4f60\u4f1a\u6210\u4e3a\u4e00\u4e2a\u51fa\u8272\u7684\u5b89\u5353\u5f00\u53d1\u8005\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5728\u8fd9\u7bc7\u6587\u7ae0\u4e2d\uff0c\u6211\u4eec\u5c06\u5b66\u4e60\u5982\u4f55\u4f7f\u7528Java\u5f00\u53d1\u4e00\u4e2a\u7b80\u5355\u7684\u5b89\u5353app\u3002\u5728\u5f00\u59cb\u4e4b\u524d\uff0c\u8bf7\u786e\u4fdd\u4f60\u5df2\u7ecf\u5b89\u88c5\u4e86Android Studio\uff0c\u8fd9\u662fGoogle\u5b98\u65b9\u652f\u6301\u7684\u5b89\u5353\u5e94\u7528\u5f00\u53d1\u8f6f\u4ef6\u3002\u4f60\u53ef\u4ee5\u4ece\u8fd9\u91cc\u4e0b\u8f7d\uff1ahttps<\/p>\n","protected":false},"author":16,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[22066,3379,171,22067,322],"class_list":{"0":"post-14707","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"hentry","6":"category-zuoapp","7":"tag-app","8":"tag-3379","9":"tag-171","11":"tag-322"},"_links":{"self":[{"href":"https:\/\/www.zhidianwl.com\/zhidian\/wp-json\/wp\/v2\/posts\/14707","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.zhidianwl.com\/zhidian\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.zhidianwl.com\/zhidian\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.zhidianwl.com\/zhidian\/wp-json\/wp\/v2\/users\/16"}],"replies":[{"embeddable":true,"href":"https:\/\/www.zhidianwl.com\/zhidian\/wp-json\/wp\/v2\/comments?post=14707"}],"version-history":[{"count":1,"href":"https:\/\/www.zhidianwl.com\/zhidian\/wp-json\/wp\/v2\/posts\/14707\/revisions"}],"predecessor-version":[{"id":14790,"href":"https:\/\/www.zhidianwl.com\/zhidian\/wp-json\/wp\/v2\/posts\/14707\/revisions\/14790"}],"wp:attachment":[{"href":"https:\/\/www.zhidianwl.com\/zhidian\/wp-json\/wp\/v2\/media?parent=14707"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.zhidianwl.com\/zhidian\/wp-json\/wp\/v2\/categories?post=14707"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.zhidianwl.com\/zhidian\/wp-json\/wp\/v2\/tags?post=14707"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}