源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

Android学习笔记(二)App工程文件分析

  • 时间:2022-06-26 12:35 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:Android学习笔记(二)App工程文件分析
App工程文件分析 关于如何创建一个最简单的Android App请参照链接: 《 Android学习笔记(一)环境安装及第一个hello world 》 [url=http://www.1sucai.cn/article/52593.htm]http://www.1sucai.cn/article/52593.htm[/url] 创建完的工程文件如下图所示,本文对一些主要的文件进行分析。 [img]http://files.jb51.net/file_images/article/201407/201407301007556.png[/img] src文件分析 App源文件如图: [img]http://files.jb51.net/file_images/article/201407/201407301007557.png[/img] 打开源文件 MainActivity.java 可看到如下代码: [img]http://files.jb51.net/file_images/article/201407/201407301007558.png[/img] 源码主要功能如下: App源文件目录
package com.example.firstapp; 
导入App所需的类
import android.os.Bundle; 
import android.app.Activity; 
import android.view.Menu; 
MainActivity继承自Activity
public class MainActivity extends Activity

重载onCreate方法,使用布局文件初始化Activity
@Override
protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_main);
} 
重载onCreateOptionsMenu方法,使用布局文件初始化Menu
@Override
public boolean onCreateOptionsMenu(Menu menu) {
  // Inflate the menu; this adds items to the action bar if it is present.
  getMenuInflater().inflate(R.menu.main, menu);
  return true;
}
gen与res文件 gen文件夹下R.java文件在创建工程时自动创建,为只读文件,定义了项目所有资源的索引,里面的每个静态类都与一个资源对应。 例如: 1. 类drawable与res中包含drawable字样的文件夹关联 2. 类layout与res中layout文件夹关联 3. 类menu与res中menu文件夹关联 res文件夹下是App所使用的资源文件,其中: 1. drawable与icon相关 2. layout与布局相关 3. menu与menu布局相关 4. value字样的定义了项目配置中使用的值 举例: 界面中的文字 value的文件夹下的strings.xml文件中定义了名称为hello_world的字符串,其值为" hello world! " layout文件夹下的activity_main.xml中定义了Textveiw中的文字为hello_world字符串。 Android Menifest.xml App的主要配置文件,内容如下: 配置App信息
package="com.example.firstapp"
android:versionCode="1"
android:versionName="1.0"  
配置SDK等级
android:minSdkVersion="8"
android:targetSdkVersion="19"
配置App资源 配置App的图标、名称及主题等,其资源与res文件夹对应。 
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" 
  配置App的Activity和App名称
android:name="com.example.firstapp.MainActivity"
android:label="@string/app_name" 
配置App的intent-filter
action

  android:name="android.intent.action.MAIN"
category

  android:name="android.intent.category.LAUNCHER"

最后 以上为App工程文件分析,个人理解,仅供参考。
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部