標籤:
在忙了兩天的android學習過程中終於得到了一些自己覺得滿意的收穫。
首先是建立了android project 然後做了一些button和toast任重道遠仍需努力。
在開始我先說一下需要做的步驟:
首先你需要在res檔案下的layout中建立一個屬於你當前活動的布局(xml),碼代碼ing,之後在你的包檔案下的java檔案中載入你的你的布局,如果你想要做Toast那麼看接下來的代碼就OK了,下面的代碼是手打複習版本的,可能會出現錯誤,請見諒。
首先,開始是做Button。
1 <?xml version="1.0" encoding="utf-8"?> 2 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 3 android:layout_width="wrap_content" 4 android:layout_height="wrap_content" 5 android:orientation="vertical" > 6 7 <Button 8 android:id = "@+id/button" 9 adnroid:layout_width="match_parent"10 android:layout_height="match_parent"11 android:text="Button" //button上顯示的文字12 android:textSize="20px" //控制文字大小 13 /> 14 15 </LinearLayout>
製作完Button之後應該將你的Button載入到你的布局中並且做一個Toast出現;
看到這長長的包名,我表示被玩了好久才全部找出來
package com.example.***; //***是你的項目名字import android.app.Activity;import android.os.Bundle;import adnroid.widget.Button;import android.widget.Toast;import android.view.Window;import android.view.View.onClickListener;import android.view.View;public class MyActivity extends Activity{ @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); //requestWindowFeature(Window.FEATURE_NO_TITLE); //表示把FEATURE拼錯了好多遍,查了好久的錯誤,作用是去除標題列 setContentView(R.layout.firstlayout); Button toast = (Button) findViewById(R.id.button); toast.setOnClickListener(new OnClickListener() { //這邊需要載入一個android.view.View.OnClickListener的包, @Override public void onCreat(View v){ //View需要android.view.View 包才能夠使用 Toast.makeText(MyActivity.this,"Toast",Toast.LENGTH_SHORT).show(); //}});}
android 04.16