开发平台:windows7+Eclipse+andriod SDK(24.0)+ADT(23.0.4)。这个环境的搭建在前一篇文章(Mobile testing下的appium测试)里面已经描述了。

具体步骤:

1,建一个android project,填好项目名,然后再选择minimum requeired SDK时:如果选择的这个sdk版本低于3.0那么创建安装工程的同时也会创建一个appcomat_v7工程,这个主要是为了兼容低版本的安卓系统的;如果不想要这个v7工程的话,就选择minimum requeired SDK大于3.0,这里我选的是API19 (android 4.4),编译的版本也是这个。然后后面都点下一步就可以了,当然在launcher icon和Activity页面可以配置自己需要的icon和activity。

2,工程建好后,有3个xml需要修改:AndroidManifest.xml,res/layout/main.xml和res/values/strings.xml。它们的作用分布是:

AndroidManifest:它是Android程序的全局配置文件,是每个 android程序中必须的文件。它位于我们开发的应用程序的根目录下,描述了package中的全局数据,包括package中暴露的组件 (activities, services, 等等),以及他们各自的实现类,各种能被处理的数据和启动位置等重要信息。

main: App主窗体布局文件,你的应用长什么样都在这边定义,有Design和Text两种模式

strings:可以理解为i18n文件,这个文件用来存放程序调用的各种字符串

manifest.xml:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.myAndroid3"
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="@android:style/Theme.Black.NoTitleBar" >
<activity android:name="com.example.myAndroid3.myActivity" android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN"></action>
<category android:name="android.intent.category.LAUNCHER"></category>
</intent-filter>
</activity>
<activity android:name="com.example.myAndroid3.mySecond" android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.category.DEFAULT"></action>
</intent-filter>
</activity>
</application> </manifest>

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="fill_parent"
android:layout_height="fill_parent">
<TextView
android:layout_width="fill_parent"
android:layout_height="180dp"
android:text="@string/default_message"
android:id="@+id/hellotextView" android:textColor="#00ff00" android:gravity="center"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/button_send"
android:id="@+id/hellobutton" android:layout_gravity="center"/>
</LinearLayout>

strings.xmls:

<resources>
<string name="app_name">myAndroid3</string>
<string name="button_send">Say something</string>
<string name="default_message">Click button below!</string>
<string name="interact_message">You just clicked on the Button!</string>
</resources>

3,然后新建一个类,我这里是myActivity,然后加上如下代码:

public class myActivity extends Activity{
/**
* Called when the activity is first created.
*/
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
//定义helltobtn
Button hellobtn = (Button)findViewById(R.id.hellobutton);
//监听hellobtn
hellobtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//定义hellotextview
TextView hellotv = (TextView)findViewById(R.id.hellotextView);
//弹出toast浮动控件显示btn被点击
Toast.makeText(myActivity.this,"Clicked",Toast.LENGTH_SHORT).show();
//在textview上显示interact_message的内容
hellotv.setText(R.string.interact_message);
}
});
}
}

3,编译没错后,就可以连上真机(需打开开发者调试模式)或者模拟器,选择这个工程然后run as android application了, 然后就可以看到apk被安装,打开apk开始摇滚吧。

最新文章

  1. js的并行加载以及顺序执行
  2. 基于MVC4+EasyUI的Web开发框架经验总结(1)-利用jQuery Tags Input 插件显示选择记录
  3. 解决服务器上 w3wp.exe 和 sqlservr.exe 的内存占用率居高不下的方案
  4. Linux_几个符号命令
  5. 控制反转和spring在项目中可以带来的好处
  6. python 爬取百度云资源
  7. C语言可变参数在宏定义中的应用
  8. Nginx 变量漫谈(二)
  9. Java虚拟机体系结构
  10. 从 JavaScript 到 TypeScript 系列
  11. WebServeice 动态代理类
  12. Java的一些基本术语
  13. BZOJ5249 九省联考2018IIIDX(线段树+贪心)
  14. [JS] ECMAScript 6 - Prototype : compare with c#
  15. Centos7 安装sz,rz命令
  16. windows 服务器MYSQL 数据库安装配置
  17. python代码实现stack和queue
  18. solr .Net端(SolrNet)
  19. How to use jQuery countdown plugin
  20. Makefile编写 二

热门文章

  1. 0环境设置 - Statspack设置
  2. String与StringBuilder
  3. lintcode :Remove Duplicates from Sorted List 删除排序链表中的重复元素
  4. ASP.NET获取路径的方法
  5. C++:类的创建
  6. sql中exists,not exists的用法
  7. 【C#设计模式——创建型模式】抽象工厂模式
  8. linq to Entity 数据库除了有主键还有唯一索引,是不是不能更新
  9. StaggeredGridLayoutManager
  10. Android studio在真机上进行调试