真不知道自己写这些东西做什么,就说说Android开发学习入门之HelloWorld 。
1.AndroidManifest.xml
- <manifest xmlns:android="http://schemas.android.com/apk/res/android"
- package="com.android.helloWorld"
- android:versionCode="1"
- android:versionName="1.0">
- <application android:icon="@drawable/icon" android:label="@string/app_name">
- <activity android:name=".HelloWorld"
- android:label="@string/app_name">
- <intent-filter>
- <action android:name="android.intent.action.MAIN" />
- <category android:name="android.intent.category.LAUNCHER" />
- </intent-filter>
- </activity>
- </application>
- </manifest>
这里表明的是启动了一个程序,程序有个ico,在相应的目录里可以找到,用作程序的图标显示,还有程序的名字。这里说明了字符串的使用方法,记得字符串要这么使用,但到底这个字符串是在哪放着呢,下面会有介绍。 还有就是那了一个activity,应该类似一个窗口吧,名字是HelloWorld,前面的点有没有好像没有关系,我在学习的时候会注意下的。下面android.intent.action.MAIN说明了这个窗口用作主窗口,android.intent.category.LAUNCHER是说把这个程序放入到程序列表里面。
2.string.xml
- <?xml version="1.0" encoding="utf-8"?>
- <resources>
- <string name="hello">Hello World, HelloWorld!</string>
- <string name="app_name">HelloWorld</string>
- </resources>
这里面存放的就是字符串一类的数据的了,比如这里也可以定义些颜色什么的。使用方法在上面已经有了。
3.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>
很多ui界面类的软件都是使用标记来表明显示内容的。我们可以使用一些拖动的ui工具来快速产生这个文件。 4.HelloWorld.java
- package com.android.helloWorld;
-
- import android.app.Activity;
- import android.os.Bundle;
-
- public class HelloWorld extends Activity {
- /** Called when the activity is first created. */
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.main);
- }
- }
这里也就是最前面提到了源码了,指定了一开始就要执行这个文件,这个文件继承自一个activity,在创建的时候调用父的创建函数,并把我们前面写的代码ui界面的xml文件显示出来。 我想整个过程这样就都做完了,在这最简单的程序里也可能有理解不正确的地方。断续学习吧!