深入了解HelloAndroid下的三个文件
来源:互联网 发布:ant windows 64位下载 编辑:程序博客网 时间:2024/06/02 02:23
下面列出我们要掌握的几个重要文件
HelloAndroid.java:
代码如下:
- 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
代码如下:
- <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配置文件:
代码如下:
- <?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 0
- 深入了解HelloAndroid下的三个文件
- 深入了解HelloAndroid下的三个文件——转载出处:coder-pig
- Caffe框架,了解三个文件
- 深入了解INF文件
- 深入了解INF文件
- 深入了解INF文件
- HelloAndroid
- HelloAndroid
- HelloAndroid
- HelloAndroid
- HelloAndroid
- HelloAndroid
- 了解项目的三个角度
- 深入了解UNIX文件权限
- 深入了解linux下的last命令及其数据源
- Java的深入了解
- 深入的了解继承
- 内存的深入了解
- SpringMVC入门 -- WebMVC简介
- 51单片机DS1302实时时钟驱动程序
- 理解Python中的装饰器
- Android ADT与SDK的更新问题解决方法
- js效果
- 深入了解HelloAndroid下的三个文件
- C++之测试snmp的注册模块
- linux ssh自动登陆
- 文件操作
- PCL库尝试
- 小猪的Android入门之路 day 1
- SGU 495 Kids and Prizes [期望]
- c# 模拟表单提交,post form 上传文件、大数据内容
- 小猪的Android入门之路 Day 2