android 04.16

來源:互聯網
上載者:User

標籤:

  在忙了兩天的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

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.