TextViewクラス

ViewクラスTextViewクラス

TextViewクラスとは?

 状態:-  閲覧数:1,411  投稿日:2013-12-18  更新日:2018-08-02  

テキストを表示するクラス


文字を表示する機能を持つ

レイアウトの子要素
・R.layout.mainが示すmain.xmlファイルなどに記述

クラス構成

 閲覧数:361 投稿日:2013-12-18 更新日:2014-03-17 

親クラス



java.lang.Object
  ↳ android.view.View
   ↳ android.widget.TextView



XML属性一覧

 閲覧数:404 投稿日:2014-03-15 更新日:2014-09-20 
XML属性一覧
要素 意味
android:drawableLeft 画像をテキストの左側に描画
android:drawableRight 画像をテキストの右側に描画
android:drawableTop 画像をテキストの上側に描画

Viewクラスより継承されたXML属性一覧
要素 意味
android:padding 上下左右のパディング
android:paddingTop 上のパディング
android:paddingBottom 下のパディング
android:paddingLeft 左のパディング
android:paddingRight 右のパディング


メソッド一覧

 閲覧数:479 投稿日:2014-03-16 更新日:2014-03-31 
setText
・文字列の変更
※引数で直接文字列指定するか、文字列のリソースIDを指定

コード例

 閲覧数:374 投稿日:2014-03-16 更新日:2014-03-31 

例1


▼/HelloAndroid/src/android/style/HelloAndroidActivity.java
package android.style;

import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;

public class HelloAndroidActivity extends Activity {
   /** Called when the activity is first created. */
   @Override
   public void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);
       setContentView(R.layout.main);
       
       TextView tview = (TextView)findViewById(R.id.textView1);
       tview.setText("動的に設定します");
   }
}


・xml … レイアウト
▼/HelloAndroid/res/layout/main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
   android:layout_width="fill_parent"
   android:layout_height="fill_parent"
   android:orientation="vertical" >

   <TextView
       android:layout_width="fill_parent"
       android:layout_height="wrap_content"
       android:text="@string/hello" />



   <Button
       android:id="@+id/button1"
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:text="@string/button_str1" />

   <TextView
       android:id="@+id/textView1"
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:text="TextView" />

</LinearLayout>



コメント投稿(ログインが必要)