下面列出我们要掌握的几个重要文件

HelloAndroid.java:
代码如下:
[java] view
plaincopy


- import android.os.Bundle;
- import android.app.Activity;
-
-
- public class MainActivity extends Activity {
-
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- }
- }
代码解析:

布局文件main.xml
代码如下:
[html] view
plaincopy


- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:tools="http://schemas.android.com/tools"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:orientation="vertical"
- tools:context=".MyActivity">
-
- <TextView
- android:text="@string/hello_world"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content" />
-
- </LinearLayout></span>
代码解释:
我们定义了一个LinearLayout线性布局
在xml命名空间中定义我们所需要使用的架构,来自于①

AndroidManifest.xml配置文件:
代码如下:
[html] view
plaincopy


- <?xml version="1.0" encoding="utf-8"?>
- <manifest xmlns:android="http://schemas.android.com/apk/res/android"
- package="example.jay.com.myfirstapplication"
- android:versionCode="1"
- android:versionName="1.0" >
-
- <uses-sdk
- android:minSdkVersion="8"
- android:targetSdkVersion="21" />
-
- <application
- android:allowBackup="true"
- android:icon="@drawable/ic_launcher"
- android:label="@string/app_name"
- android:theme="@style/AppTheme" >
- <activity
- android:name=".MainActivity"
- 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><strong>
- </strong>
代码解释:

除了上述的内容外,
①如果app包含其他组件的话,都要使用类型说明语法在该文件中进行声明
Server:<server>元素 BroadcastReceiver<receiver>元素 ContentProvider<provider>元素
IntentFilter<intent-filter>元素
②权限的声明:
在该文件中显式地声明程序需要的权限,防止app错误地使用服务, 不恰当地访问
资源,最终提高android app的健壮性
android.permission.SEND_SMS 有这句话表示app需要使用发送信息的权限,安装的时候就会提示用户,
相关权限可以在sdk参考手册查找
本文链接:https://it72.com/10626.htm