AndroidAPP开发入门教程Word文档格式.docx

上传人:b****2 文档编号:6038901 上传时间:2023-05-05 格式:DOCX 页数:9 大小:417.51KB
下载 相关 举报
AndroidAPP开发入门教程Word文档格式.docx_第1页
第1页 / 共9页
AndroidAPP开发入门教程Word文档格式.docx_第2页
第2页 / 共9页
AndroidAPP开发入门教程Word文档格式.docx_第3页
第3页 / 共9页
AndroidAPP开发入门教程Word文档格式.docx_第4页
第4页 / 共9页
AndroidAPP开发入门教程Word文档格式.docx_第5页
第5页 / 共9页
AndroidAPP开发入门教程Word文档格式.docx_第6页
第6页 / 共9页
AndroidAPP开发入门教程Word文档格式.docx_第7页
第7页 / 共9页
AndroidAPP开发入门教程Word文档格式.docx_第8页
第8页 / 共9页
AndroidAPP开发入门教程Word文档格式.docx_第9页
第9页 / 共9页
亲,该文档总共9页,全部预览完了,如果喜欢就下载吧!
下载资源
资源描述

AndroidAPP开发入门教程Word文档格式.docx

《AndroidAPP开发入门教程Word文档格式.docx》由会员分享,可在线阅读,更多相关《AndroidAPP开发入门教程Word文档格式.docx(9页珍藏版)》请在冰点文库上搜索。

AndroidAPP开发入门教程Word文档格式.docx

二、代码编写

做好准备工作后,终于可以开始写我们的helloandroid了,在开始编写代码之前,我们先了解几个文件:

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

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

src/com/example/helloandroid/MyActivity.java这个就是我们的主程序类,等下要实现的功能都在这个文件里添加

首先为应用添加一个id为hellotextView的textview和一个id为hellobutton的button,mail.xml代码如下:

复制代码代码如下:

<

?

xmlversion="

1.0"

encoding="

utf-8"

>

LinearLayoutxmlns:

android="

 

android:

orientation="

vertical"

layout_width="

fill_parent"

layout_height="

>

<

TextView

180dp"

text="

@string/default_message"

id="

@+id/hellotextView"

textColor="

#00ff00"

gravity="

center"

/>

Button

wrap_content"

@string/button_send"

@+id/hellobutton"

layout_gravity="

/LinearLayout>

代码和控件用到的字符串定义如下:

resources>

stringname="

app_name"

helloandroidbyhiwanz<

/string>

button_send"

Saysomething<

default_message"

Clickbuttonbelow!

interact_message"

YoujustclickedontheButton!

/resources>

主程序中定义button点击后改变textview显示的文本,并且弹出Toast提示信息,代码如下:

packagecom.example.helloandroid;

importandroid.app.Activity;

importandroid.os.Bundle;

importandroid.view.View;

importandroid.widget.Button;

importandroid.widget.TextView;

importandroid.widget.Toast;

publicclassMyActivityextendsActivity{

/**

*Calledwhentheactivityisfirstcreated.

*/

@Override

publicvoidonCreate(BundlesavedInstanceState){

super.onCreate(savedInstanceState);

setContentView(R.layout.main);

//得到按钮实例

Buttonhellobtn=(Button)findViewById(R.id.hellobutton);

//设置监听按钮点击事件

hellobtn.setOnClickListener(newView.OnClickListener(){

publicvoidonClick(Viewv){

//得到textview实例

TextViewhellotv=(TextView)findViewById(R.id.hellotextView);

//弹出Toast提示按钮被点击了

Toast.makeText(MyActivity.this,"

Clicked"

Toast.LENGTH_SHORT).show();

//读取strings.xml定义的interact_message信息并写到textview上

hellotv.setText(R.string.interact_message);

}

});

}

代码写好后,电脑通过USB数据线连接手机,手机系统设置里的开发人员选项里打开USB调试,在IDE中直接点Run就可以在手机上看到运行的效果了。

应用打包

应用开发完成后就要打包发布了,在IDE的Build菜单下选择GenerateSignedAPK来打包应用

在弹出的Wizard对话框中需要指定签名的Key,一开始没有Key你可以点击CreateNew来新建一个Key用于签名,填入签名所需的一些字段后生成Key文件

使用生成的Key来签名应用包

完成编译后会在刚才我们设置的DesignationAPKpath下生成我们的helloandroid.apk应用包,接下来要怎么安装应用应该不用说了吧,我们的第一个AndroidApp就这样诞生了。

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > 总结汇报 > 学习总结

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2