进入第一个Android应用界面
前话
距离上次学习Android已经过去了半年了,这半年我干嘛去了?
嘛相信大家也没兴趣了解,简单来说就是我学习了周边的知识技术,最后终于转回Android。
感觉开发一个Android需要很多知识吧,一个完整的Android网络应用=Java编程基础+Web后台开发+服务器搭建+Android开发技术+必要的美工基础
然后我只是泛泛了解了这些,就匆忙转回(就是感觉拖越久就越容易忘光)
很多基础我就不解释了,因为网上真的一大把。。。。。。
不废话了,下面正题。
准备
开发工具为Android Studio
安卓虚拟机使用Genymotion
过程
第一步,创建新的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应用界面的更多相关文章
- Android studio 开发一个用户登录界面
Android studio 开发一个用户登录界面 activity_main.xml <?xml version="1.0" encoding="utf-8&qu ...
- Android开发学习1----AndroidStudio的安装、创建第一个Android Studio文件、Android Studio界面介绍和HelloWord!
移动开发的工具有很多:Android Studio,eclipse,Hbuilder等,其中,现如今最火的开发工具是Android Studio,Android Studio是谷歌自己推出的一款集成开 ...
- 3.创建第一个android项目
安卓开发学习笔记 1.安卓开发之环境搭建 2.SDK目录结构和adb工具及命令介绍 3.创建第一个android项目 1.打开Eclipse,选择File——>new——>others.. ...
- 创建一个Android项目
当我们的eclipse安装了SDK后,点击Window-->Perference-->DDMS.eclipse界面立即转为DDMS界面. 这时,我们可以打开我们的服务端(安卓模拟器或者是我 ...
- 认识Activity,创建第一个android应用-Hello Word
2016-04-05 配置好Java.eclipse和Android环境就花费了一天时间.下载SDK真是费了不少时间.现在终于找到解决SDK更新的好方法了(更新自己电脑上的hosts文件,就可以使用G ...
- Android开发自学笔记(Android Studio1.3.1)—2.开始第一个Android应用
一.前言 使用Android Studio开发Android应用是一件非常简单的事情,因为它会帮你自动完成很多工作.本篇我们主要完成一个单击按钮在文本框显示当前时间的简单应用,借此来演示一下 ...
- Android典型界面设计——ViewPage+Fragment实现区域顶部tab滑动切换
一.问题描写叙述 本系列将结合案例应用,陆续向大家介绍一些Android典型界面的设计,首先说说tab导航,导航分为一层和两层(底部区块+区域内头部导航).主要实现方案有RadioGroup+View ...
- 跟我学android-使用Eclipse开发第一个Android应用(三)
打开Eclipse,选择 File—New –Android Application Project Application Name 就是我们的 应用名称,也是我们在手机应用程序列表里看到的名称. ...
- 创建一个Android工程
Creating an Android Project 原文演示了怎么通过Android Studio和命令行两种方式来创建一个Android工程. 原文链接:http://developer.and ...
随机推荐
- P3401: [Usaco2009 Mar]Look Up 仰望
这道题第一眼还以为是树状数组,于是乎打着打着也是能过的 ; var n,i,j,maxx:longint; h,l:array[..] of longint; p:array[..] of longi ...
- String、StringBuilder、StringBuffer
String String ...
- PostgreSQL中的引号和null
今天工作时写了一个sql,但是PostgreSQL总是提示有语法错误,简单的做个记录: 问题1.'' 和“”单引号和双引号 举个例子: #.select id, delivery_d ...
- windows环境下svn同步web文件[转]
windows环境下svn同步web文件 SVN在团队开发中使用非常普遍,是一个很方便的版本控制系统. 如果要是能将SVN服务器上的数据自动发布到Web服务器,那将是整个项目开发.测试更加便捷.利用S ...
- jquery 提示简单效果插件 cluetip
介绍一个不错的jquery插件-cluetip 我们在做web项目的时候,经常会使用到提示效果.html自带的提示效果是label标签的title,但是这个效果过于简单和难看,并且不方便调整样式. 今 ...
- ios containerViewController
- (void)replaceViewController:(UIViewController *)existingViewController withViewController:(UIViewC ...
- Feature Engineering versus Feature Extraction: Game On!
Feature Engineering versus Feature Extraction: Game On! "Feature engineering" is a fancy t ...
- FormCreate & FormActivate & FormShow执行顺序演示
procedure TForm1.FormCreate(Sender: TObject);begin form1.Caption:=form1.Caption +'+Create'; end; pr ...
- NGUI 实现 透明底图遮罩 && 人物像素变黑
今天 UI 那边要求实现一个 透明底图遮罩 与 变黑 的效果. 刚开始考虑使用 shader 实现一个 网上搜了一下,发现了这个,但是底图需要不透明才行,不然他会把 底图的不遮罩部分的透明部分 进行颜 ...
- 如何使用CSS3创建一个漂亮的图标
演示 下载 今天,我想展示给你一个巧妙的花招.我们将创建一个纯CSS3文本图标.更让人震惊的是,这效果将只需要一个HTML元素. 游戏的计划 创建一个矩形盒子 设置圆角 使用伪类元素创建一个卷角效果 ...