本周get一个新技能,做一个简单的安卓界面。
简单操作一哈!!!
1、打开eslipse->file->New->Android Application Project
随后就会弹出界面,填写安卓工程的名称。
!!!注意:Pakage Name 不可以出现中文哦

2、点击Next

3、点击Next,根据自己的喜好做以下设置。(看看英文就能了解是啥意思,自己设置哦)

4、全选默认就好,点击Next

5、依然选择默认,Finish

6、接下来就是愉快的代码时间
MainActivity.java
package com.example.android;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
activity_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="45dp"
android:background="#D4B00B" //选择背景颜色
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello Wrold"
android:textSize="18sp"
android:textColor="#ffffff"
android:layout_centerVertical="true"
android:layout_marginLeft="30dp"
/>
</RelativeLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true"
android:layout_marginBottom="50dp"
>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Welcome"
android:textSize="25sp"
android:textColor="#f0f0f0"
/>
</RelativeLayout>
</RelativeLayout>
7、选择“Android”工程右键->Run As -> Android Application
连上手机试试效果

你成功了吗?
快去试试吧
本文详细介绍了使用Eclipse创建并运行一个基本的Android应用程序的过程。从新建项目到编写MainActivity代码,再到设计activity_main.xml布局文件,最后运行应用并查看手机上的效果。适合初学者快速入门。
300

被折叠的 条评论
为什么被折叠?



