本週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
連上手機試試效果
你成功了嗎?
快去試試吧