进入第一个Android应用界面
来源:互联网 发布:朝鲜第五次核试验知乎 编辑:程序博客网 时间:2024/05/21 18:42
前话
距离上次学习Android已经过去了半年了,这半年我干嘛去了?
嘛相信大家也没兴趣了解,简单来说就是我学习了周边的知识技术,最后终于转回Android。
感觉开发一个Android需要很多知识吧,一个完整的Android网络应用=Java编程基础+Web后台开发+服务器搭建+Android开发技术+必要的美工基础
然后我只是泛泛了解了这些,就匆忙转回(就是感觉拖越久就越容易忘光)
很多基础我就不解释了,因为网上真的一大把。。。。。。
不废话了,下面正题。
准备
开发工具为Android Studio
安卓虚拟机使用Genymotion
安卓API文档国内镜像
过程
第一步,创建新的Android空项目
Application name:应用名,项目创建成功后会创建相应名的项目文件夹,该应用名后面可在AndroidManifest文件中更改
Company Domain:域名,对应包名,没错!我的博客新域名 pwcong.me
选择最低支持的SDK版本,低于选择版本的手机无法安装,防止低版本对某特安卓新特性的不适应
空项目目录如下图所示:
第二步,创建一个界面
1.导入自己喜欢的界面图片到res->mipmap文件夹内
res文件夹中有drawable文件夹和mipmap文件夹,许多人会混淆图片存放位置放到哪里,官方解释是:
drawable/
For bitmap files (PNG, JPEG, or GIF), 9-Patch image files, and XML files that describe Drawable shapes or Drawable objects that contain multiple states (normal, pressed, or focused). See the Drawable resource type.
mipmap/
For app launcher icons. The Android system retains the resources in this folder (and density-specific folders such as mipmap-xxxhdpi) regardless of the screen resolution of the device where your app is installed. This behavior allows launcher apps to pick the best resolution icon for your app to display on the home screen. For more information about using the mipmap folders, see Managing Launcher Icons as mipmap Resources.
2.res文件夹右键添加一个Android Resource File,选择layout布局文件,在布局文件内添加image控件,设置image引用导入的界面图片
activity_main.xml源码如下:
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <ImageView android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/imageView" android:src="@mipmap/img" android:scaleType="centerCrop" /></LinearLayout>
第三步,创建一个Activity绑定界面
MainActivity.java 源码:
package me.pwcong.myfirstapp.activity;import android.app.Activity;import android.os.Bundle;import me.pwcong.myfirstapp.R;public class MainActivity extends Activity { //该Activity创建时执行该方法 @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); //绑定界面布局文件 setContentView(R.layout.activity_main); }}
第四步,编辑AndroidManifest文件
AndroidManifest文件源码:
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="me.pwcong.myfirstapp"> <application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:supportsRtl="true" android:theme="@style/AppTheme"> <activity android:name=".activity.MainActivity"> <intent-filter> //注意,以下两条标记程序的入口Activity <action android:name="android.intent.action.MAIN"/> <category android:name="android.intent.category.LAUNCHER"/> </intent-filter> </activity> </application></manifest>
最后,运行看效果
重点是程序如何进入第一个界面
上面是一个简单至极的实例,打开程序显示一张图片。
其中过程简单来说就是系统Launcher查找被标记为Main和Launcher的应用程序Activity来启动应用,就是AndroidManifest内的一段:
<action android:name="android.intent.action.MAIN"/><category android:name="android.intent.category.LAUNCHER"/>
两者作用如下:
- android.intent.action.MAIN:决定应用程序最先启动的Activity
- android.intent.category.LAUNCHER:决定应用程序是否显示在程序列表里
如果只有一个activity的应用程序只声明了 android.intent.action.MAIN ,没有声明 android.intent.category.LAUNCHER,运行将报错
如果存在多个activity都声明了android.intent.action.MAIN与android.intent.category.LAUNCHER,将会有多个图标显示在桌面上
- 进入第一个Android应用界面
- IOS第一个界面应用
- 使用kotlin编写第一个Android应用界面
- 关于android程序进入第一个界面出现空白的解决方案
- 第一个Android应用
- 第一个android应用
- 第一个Android应用
- 第一个Android应用
- Android 仿微信的应用进入界面
- Android进入应用下载评分界面
- 第一个登录界面web应用
- Android的第一个应用
- android第一个应用-helloWorld
- 创建第一个android应用
- 第一个 android 的界面程序
- Android Hello Android 第一个Android 应用
- 【Android】进入应用和切换界面时闪屏的问题
- android Home 之后重新进入 保持应用操作界面
- Java学习随想
- [2016.4][京东暑期实习笔试]三子棋
- 关于python中的unicode字符串的使用
- c++ 嵌套类
- Thinkphp关联模型使用field或getField函数
- 进入第一个Android应用界面
- 我的第一篇博客
- 高通平台LCD移植概述
- 接口的学习笔记
- Codeforces Round #316 (Div. 2) D 【dfs序+二分】
- delphi idhttp post
- 京东笔试题 年终奖
- c++作业3
- 基础DOM和CSS操作