AndroidでとりあえずタイトルっぽくHello World!もしてみた
昨日はそのままHello Worldとしてみただけなんですが、今回はiPhoneのNabigationBarのようにHello Worldと出してみます。
iPhoneより分かりやすいような気がする。
import android.app.Activity; import android.graphics.Color; import android.os.Bundle; import android.view.Gravity; import android.widget.LinearLayout; import android.widget.TextView; public class top extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // レイアウトビューを作成 LinearLayout linearLayout = new LinearLayout(this); // 垂直方向にViewを追加する linearLayout.setOrientation(LinearLayout.VERTICAL); // 親ビューとして配置する setContentView(linearLayout); // TextViewを作成 TextView title = new TextView(this); // 文字を指定する title.setText("Hello World!"); // 背景色をグレーに設定 title.setBackgroundColor(Color.rgb(128, 128, 128)); // TextViewの高さを40ピクセルに指定 title.setHeight(40); // フォントサイズを20ピクセルに指定 title.setTextSize(20.0f); // 上下左右で中央に指定する title.setGravity(Gravity.CENTER); // 親ビューにTextViewを子ビューとして配置する linearLayout.addView(title); } }
出た、出た!