参考罗升阳《Android系统源代码情景分析》
在Android源码中,我们通常把实验性质的Android APP放在packages/experimental目录下。对于一个简单的应用程序,他的目录结构如下
Android应用程序工程一般包含有一个源代码目录src、一个资源目录res、一个配置文件AndroidManifest.xml和一个编译脚本文件Android.mk
HelloAndroid.java
package com.tian.hello; import android.app.Activity;
import android.os.Bundle;
import android.util.Log; public class HelloAndroid extends Activity {
private final static String LOG_TAG = "com.tian.hello.HelloAndroid"; @Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main); Log.i(LOG_TAG, "HelloAndroid Activity Created.");
}
}
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"
android:gravity="center">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:text="@string/hello_android" >
</TextView>
</LinearLayout>
strings.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">HelloAndroid</string>
<string name="hello_android">Hello Android</string>
</resources>
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.tian.hello"
android:versionCode="1"
android:versionName="1.0">
<application android:icon="@drawable/icon"
android:label="@string/app_name">
<activity android:name=".HelloAndroid"
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>
Android.mk
LOCAL_PATH:= $(call my-dir) include $(CLEAR_VARS) LOCAL_MODULE_TAGS := optional LOCAL_SRC_FILES := $(call all-subdir-java-files) LOCAL_PACKAGE_NAME := HelloAndroid include $(BUILD_PACKAGE)
源码中使用主题
android:theme="@android:style/Theme.Dialog