命令行构建安卓工程,了解工程原理

首先安装android SDK;PATH配置引入tools;即可使用android命令 


1.创建工程

android create project -n HelloWorld -t 1 -p HelloWorld -k org.crazyit.helloworld -a HelloWorld

-n   工程名

-t    工程对应的安卓平台ID,可用android list targets查看对应ID

-p   工程保存路径

-k   给工程报名

-a   制定activity名称

该命令将会在当前路径下创建hello world文件夹,文件夹中即为所创建工程;

res下存放各种资源,如layout存放界面布局文件;

src下存放Java源码;

build.xml为ant生成文件;



2.开发自己的应用:布局用户界面

android:id="@+id/show"  标识

修改./HelloWorld/res/layout/main.xml,设计用户应用界面

    <TextView
        android:id="@+id/show"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerInParent="true"
        android:text="@string/hello_world" />

    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/show"
        android:layout_centerInParent="true"
        android:onClick="clickHandler"
        android:text="@string/click" />
</LinearLayout>
界面预期结果:



3. 开发自己的应用:补充Java代码

进入./HelloWorld/src/org/crazyit/helloworld/HelloWorld.java,添加动作

package org.crazyit.helloworld;

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.TextView;

public class HelloWorld extends Activity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.hello_world);
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.hello_world, menu);
		return true;
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		// Handle action bar item clicks here. The action bar will
		// automatically handle clicks on the Home/Up button, so long
		// as you specify a parent activity in AndroidManifest.xml.
		int id = item.getItemId();
		if (id == R.id.action_settings) {
			return true;
		}
		return super.onOptionsItemSelected(item);
	}
	//添加动作
	public void clickHandler(View source){
		TextView tv = (TextView) findViewById(R.id.show);
		tv.setText("hello android!\n" + new java.util.Date());
	}
}

4. 把工程运行起来 go!

使用ant将工程打包运行 ant install

clean

debug

release

test

install

uninstall


PS:res中使用了资源@string,修改./HelloWorld/res/values/string.xml添加对应关系

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string name="app_name">HelloWorld</string>
    <string name="hello_world">Hello World !</string>
    <string name="click">点击</string>
</resources>



工程清单文件AndroidManifest.xml


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值