三年多的时间以来,我以为我会慢慢忘记Android,但是好像这是我留下来的遗憾一样,永远都挥之不去。正好这几天看了梅兄的学习笔记,决定再一次把Android捡起来。
在开始之前,刚刚得到一个消息就是我的第一枚外甥女出生了,仅此纪念~!!!
项目的目录结构如图。
src:java源码目录
gen:编译生产文件的目录
assets:资源文件目录,可以放任何类型的文件,不会再R文件中生成对应的ID
res:资源文件目录,里面的文件都会在R文件中生成对应的ID
activity_activity01.xml 页面布局文件。
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.activity_01.Activity01" >
<TextView
android:id="@+id/myTextView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<Button
android:id="@+id/myButton"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/myTextView"/>
</RelativeLayout>
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.activity_01"
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="@style/AppTheme" >
<activity
android:name=".Activity01"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Activity01.java
package com.example.activity_01;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
/**
* 创建Actity要点
* 1.一个Activity就是一个类,并且要继承Activity
* 2.复写onCreate方法
* 3.每个Activity都要在AndroidManifest.xml文件中进行配置
* 4.为每个Activity添加必要的控件
* @author Administrator
*
*/
public class Activity01 extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_activity01);
TextView textView = (TextView) findViewById(R.id.myTextView);
Button button = (Button) findViewById(R.id.myButton);
textView.setText("第一个TextView");
button.setText("第一个按钮");
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity01, menu);
return true;
}
}
这里使用的模拟器是Genymotion
参考梅亚敏的博客http://www.cnblogs.com/smyhvae/p/3863720.html
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。