【Android笔记】(1)HelloWorld

今天下午没课。今年准备做的2个项目都要和Android打交道。所以开始学习Android。心里面有点慌,觉得还是有点太广了。国创一定要申请上啊!要不然整个计划就乱了。废话不说了。。。

 

HelloWorld

 

原来从没用过java,不过还好,基本能看懂。。和刚开始MFC一个感觉。。。

 

1.基本结构。

-src:java文档

-gen:自动生成

-Adroid X.X:基础库文件

-assets:资源文件,可以为任何资源

-res:带有唯一编号的资源

 

2.helloworld

这个什么也没写。。。自动生成了。。。然后就运行就成功了,利用的是main.XML中的一些的定义,看上去就和写网页一样= =。

然后run了。。。Android虚拟机真的启动的好慢

 

3.Activity01

大致是这样的,在res中写XML,然后gen中会给xml生成唯一编码,最后src中就可以使用了。

/** *首先继承Activity类 *onCreat方法 *R.layout.main这个参数传递main.xml(添加控件)信息 * public class Activity01 extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); } }

 

·加入Button控件

<Button android:layout_width="fill_parent" android:layout_height="wrap_content" />

 

语句就像html一样。。。运行以后显示的是一个大的按钮

 

/**在main.xml中有 * android:id="@+id/myTextView" * android:id="@+id/myButton" * */ public class Activity01 extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); TextView myTextView = (TextView)findViewById(R.id.myTextView); Button myButton = (Button)findViewById(R.id.myButton); myTextView.setText("KeroEnigma的第一个TextView"); myButton.setText("第一个按钮啦啦啦啦"); } }

 

总结

Activity 控件的容器

创建一个继承Activity的类

写onCreat()

函数获取findViewById()

你可能感兴趣的:(【Android笔记】(1)HelloWorld)