java.lang.Object ↳ android.view.View ↳ android.widget.TextViewを使用します
というわけで、いろいろと値を指定して TextView をいじってみた
サンプルプログラム
- import android.app.Activity;
- import android.graphics.Color;
- import android.os.Bundle;
- import android.widget.TextView;
- public class TextViewTest extends Activity {
- TextView textView1;
- TextView textView2;
- TextView textView3;
- TextView textView4;
- TextView textView5;
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.textview);
- textView1 = (TextView) findViewById(R.id.TextView01);
- textView2 = (TextView) findViewById(R.id.TextView02);
- textView3 = (TextView) findViewById(R.id.TextView03);
- textView4 = (TextView) findViewById(R.id.TextView04);
- textView5 = (TextView) findViewById(R.id.TextView05);
- // TextView のテキストを設定
- textView1.setText("Test");
- // TextView のテキストを取得
- String text = textView1.getText().toString();
- // TextView のサイズを指定
- textView2.setTextSize(24);
- // TextView のテキストの色を指定
- textView3.setTextColor(Color.RED);
- // TextView のバックグラウンドの色を指定
- textView4.setBackgroundColor(Color.BLUE);
- // TextView のバックグラウンドのリソースを指定
- textView5.setBackgroundResource(R.drawable.icon);
- }
- }
XMLリソース
- <textview
- android:id="@+id/TextView"
- android:layout_height="wrap_content"
- android:layout_width="wrap_content"
- android:text="TextView">
- </textview>
プログラムを実行すると...

こんな感じ!
0 件のコメント:
コメントを投稿