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

HelloAndroid.java:
代码如下:
[java] view
plaincopy
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
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
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参考手册查找
收藏的用户(0) X
正在加载信息~
推荐阅读
最新回复 (0)
站点信息
- 文章2313
- 用户1336
- 访客11757472
每日一句
Life is short; Live it!
人生苦短,活出精彩。
人生苦短,活出精彩。
信鸽推送报错NSObject checkTargetOtherLinkFlagForObjc
简单利用Clover四叶草安装U盘安装黑苹果
学习使用Java注解
OllyDbg中如何找出B模块中所有调用了A模块的C方法的地方
解决SSH客户端中文乱码
10年后,Android应用程序仍然比iOS应用程序差
C++11特性里面的thread
XPosed微信自动生成二维码
解决android studio "found an invalid color"的问题
T9社区注册方法【勼适様鲃女尔懟死】
Thinkpad x1 Extreme黑苹果10.14.5安装完成
基于大白主题增加图片本地化的功能
Linux系统查看CPU使用率的几个命令
新会员