下面列出我们要掌握的几个重要文件
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)
站点信息
- 文章2303
- 用户1336
- 访客11158019
每日一句
There is always a better way.
总有更好的办法。
总有更好的办法。
IntelliJ IDEA2018~2019.1激活码-注册码
C++实现NAT检测程序
Google Play商城将85款恶意App下架
打开显示interface.png 或者显示interface.swf
【黑苹果安装】——如何在windows下操作EFI分区
Android简单树状实现
Android 8.0应用图标适配
Android Studio3.4.1更新及槽点
C/C++通过WMI和系统API函数获取系统硬件配置信息
DuiLib编译出错:成员声明中不允许限定名
Java中的(耦合)控制反转
Run-Time Check Failure #0 - The value of ESP was not properly saved across a function call. This is
#ifdef _DEBUG失效问题
新会员