Android开发学习入门之HelloWorld


真不知道自己写这些东西做什么,就说说Android开发学习入门之HelloWorld 。

1.AndroidManifest.xml

  1. <manifest xmlns:android="http://schemas.android.com/apk/res/android"  
  2.       package="com.android.helloWorld"  
  3.       android:versionCode="1"  
  4.       android:versionName="1.0">  
  5.     <application android:icon="@drawable/icon" android:label="@string/app_name">  
  6.         <activity android:name=".HelloWorld"  
  7.                   android:label="@string/app_name">  
  8.             <intent-filter>  
  9.                 <action android:name="android.intent.action.MAIN" />  
  10.                 <category android:name="android.intent.category.LAUNCHER" />  
  11.             </intent-filter>  
  12.         </activity>  
  13.     </application>  
  14. </manifest>  
这里表明的是启动了一个程序,程序有个ico,在相应的目录里可以找到,用作程序的图标显示,还有程序的名字。这里说明了字符串的使用方法,记得字符串要这么使用,但到底这个字符串是在哪放着呢,下面会有介绍。

还有就是那了一个activity,应该类似一个窗口吧,名字是HelloWorld,前面的点有没有好像没有关系,我在学习的时候会注意下的。

下面android.intent.action.MAIN说明了这个窗口用作主窗口,android.intent.category.LAUNCHER是说把这个程序放入到程序列表里面。

2.string.xml

  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <resources>  
  3.     <string name="hello">Hello World, HelloWorld!</string>  
  4.     <string name="app_name">HelloWorld</string>  
  5. </resources>  
这里面存放的就是字符串一类的数据的了,比如这里也可以定义些颜色什么的。使用方法在上面已经有了。

3.main.xml

  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  3.     android:orientation="vertical"  
  4.     android:layout_width="fill_parent"  
  5.     android:layout_height="fill_parent"  
  6.     >  
  7. <TextView    
  8.     android:layout_width="fill_parent"   
  9.     android:layout_height="wrap_content"   
  10.     android:text="@string/hello"  
  11.     />  
  12. </LinearLayout>  
很多ui界面类的软件都是使用标记来表明显示内容的。我们可以使用一些拖动的ui工具来快速产生这个文件。

4.HelloWorld.java

  1. package com.android.helloWorld;  
  2.   
  3. import android.app.Activity;  
  4. import android.os.Bundle;  
  5.   
  6. public class HelloWorld extends Activity {  
  7.     /** Called when the activity is first created. */  
  8.     @Override  
  9.     public void onCreate(Bundle savedInstanceState) {  
  10.         super.onCreate(savedInstanceState);  
  11.         setContentView(R.layout.main);  
  12.     }  
  13. }  
这里也就是最前面提到了源码了,指定了一开始就要执行这个文件,这个文件继承自一个activity,在创建的时候调用父的创建函数,并把我们前面写的代码ui界面的xml文件显示出来。

我想整个过程这样就都做完了,在这最简单的程序里也可能有理解不正确的地方。

断续学习吧!

相关内容