search
尋找貓咪~QQ 地點 桃園市桃園區 Taoyuan , Taoyuan

android程式設計實例入門 -Sample改寫分享 (2014/09/02) – jashliao部落格

android程式設計實例入門 -Sample改寫分享 (2014/09/02)

 

此範例為最簡易的Android的程式碼(03\Sample1),單純利用LinearLayout、TextView來顯示文字和外加一個按鈕,程式碼如下:

 

 

package com.jashsample;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
LinearLayout ll = new LinearLayout(this);
ll.setOrientation(LinearLayout.VERTICAL);//設定布局方式-VERTICAL(垂直)、HORIZONTAL(水平)
setContentView(ll);
TextView tv1 = new TextView(this);
tv1.setText("歡迎光臨。");
Button bt = new Button(this);
bt.setText("購買");
ll.addView(tv1);
ll.addView(bt);
}
@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;
}
}

 




熱門推薦

本文由 jashliaoeuwordpress 提供 原文連結

寵物協尋 相信 終究能找到回家的路
寫了7763篇文章,獲得2次喜歡
留言回覆
回覆
精彩推薦