Toastクラス

android.widgetToastクラス

Toastクラスとは?

 状態:-  閲覧数:1,664  投稿日:2014-03-17  更新日:2014-03-17  
・テキストを表示するクラス

クラス構成

 閲覧数:480 投稿日:2014-03-17 更新日:2014-03-17 

親クラス



java.lang.Object
   ↳ android.widget.Toast



定数一覧

 閲覧数:517 投稿日:2014-03-18 更新日:2014-03-18 
LENGTH_LONG
・トースト表示の持続期間

メソッド一覧

 閲覧数:500 投稿日:2014-03-19 更新日:2014-03-19 
makeText
・Toastクラスのオブジェクトを生成するスタティックメソッド
・引数は、アプリケーションまたはアクティビティのContextオブジェクト、表示メッセージ、持続期間、の3つのパラメータ

show
・実際の表示

コード例

 閲覧数:477 投稿日:2014-03-20 更新日:2014-03-20 

例1


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

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.widget.Toast;

public class HelloAndroid4Activity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

// Contextの取得
Context context = getApplicationContext();
// Toastオブジェクトの生成
Toast toast = Toast.makeText(context,
"Toastサンプル", Toast.LENGTH_LONG);
// 表示
toast.show();

// 以下のようにメソッドチェーンを利用して1行にすることもできる
// Toast.makeText(this, "Toastサンプル", Toast.LENGTH_LONG).show();

}
}


・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" />

</LinearLayout>



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



週間人気ページランキング / 4-17 → 4-23
順位 ページタイトル抜粋 アクセス数
1 Android用語 8
2 クラス構成 2
2 クラス構成 2
2 RecyclerView.Adapter抽象クラス 2
2 アプリケーションリソースの種類 2
2026/4/24 5:05 更新