javaocean

            BlogJava :: 首頁 :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理 ::
            3 隨筆 :: 3 文章 :: 0 評論 :: 0 Trackbacks

          1. 啟動Eclipse,點擊工具欄上的圖標(biāo)啟動創(chuàng)建Android項目向?qū)А?/p>

          2. 在對話框中輸入項目名稱等信息,如下圖。

          注意上面的對話框中Create Activity默認(rèn)是選中狀態(tài),點擊完成后會自動生成一個HelloAct的類。

          HelloAct.java

           

          package com.wm.helloandroid;

          import android.app.Activity;
          import android.os.Bundle;

          public class HelloAct extends Activity {//繼承了Activity父類
              /** 覆蓋了父類的onCreate方法, 在Activity第一次創(chuàng)建的時候調(diào)用 */
          @Override
              
          public void onCreate(Bundle savedInstanceState) {
                  
          super.onCreate(savedInstanceState);
                  setContentView(R.layout.main);
          //顯示界面
              }
          }


          在gen/com/wm/helloandroid/目錄下根據(jù)資源數(shù)據(jù)自動生成了R.java,這個類不要修改

           

          package com.wm.helloandroid;

          public final class R {
              
          public static final class attr {
              }
              
          public static final class drawable {
                  
          public static final int icon=0x7f020000;
              }
              
          public static final class layout {
                  
          public static final int main=0x7f030000;
              }
              
          public static final class string {
                  
          public static final int app_name=0x7f040001;
                  
          public static final int hello=0x7f040000;
              }
          }


          在res/layout下自動生成一個main.xml文件中定義了界面布局。
          main.xml

          <?xml version="1.0" encoding="utf-8"?>
          <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:orientation
          ="vertical"
              android:layout_width
          ="fill_parent"
              android:layout_height
          ="fill_parent"
              
          >
          <TextView  
              
          android:layout_width="fill_parent" 
              android:layout_height
          ="wrap_content" 
              android:text
          ="@string/hello"
              
          />
          </LinearLayout>

           

          在res/values下自動生成一個strings.xml文件用來定義一些字符串,顏色,形狀等資源,供程序使用。

          strings.xml

          <?xml version="1.0" encoding="utf-8"?>
          <resources>
              
          <string name="hello">Hello World, HelloAct!</string>
              
          <string name="app_name">Hello</string>
          </resources>


          在項目根目錄下自動生成了AndroidManifest.xml。這個文件是每個Android應(yīng)用程序都必須配置文件,本例不需要改動。在項目根目錄下還自動生成default.properties,也是一個需要修改的文件。

          3. 實際上,不需要寫任何代碼程序就可以運(yùn)行了。選擇項目名稱>>右鍵>>Run as>>Android Application運(yùn)行程序。

          嘗試一下將strings.xml中
           

          <string name="hello">Hello World, HelloAct!</string>


          改為

          <string name="hello">你好,Android</string>
           
          再運(yùn)行程序試試。
          posted on 2010-06-18 16:24 javaocean 閱讀(246) 評論(0)  編輯  收藏

          只有注冊用戶登錄后才能發(fā)表評論。


          網(wǎng)站導(dǎo)航:
           
          主站蜘蛛池模板: 临朐县| 榆树市| 博白县| 辉南县| 西丰县| 汉阴县| 揭西县| 天水市| 麟游县| 鹿泉市| 汤阴县| 峨山| 五河县| 资兴市| 木兰县| 湘潭县| 镇安县| 呼伦贝尔市| 衢州市| 郴州市| 珠海市| 名山县| 武冈市| 招远市| 丰城市| 鄂尔多斯市| 阿勒泰市| 麻阳| 土默特左旗| 彩票| 儋州市| 赣榆县| 上饶市| 白朗县| 克东县| 宜都市| 阳山县| 同德县| 柳林县| 繁昌县| 将乐县|