27.02.2014 Views

Android 开发教程

Android 开发教程

Android 开发教程

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

-----------------------------------<strong>Android</strong> 编 程 基 础<br />

Toast 显 示 一 个 TextView<br />

1<br />

新 建 工 程<br />

2 修 改 mainActivity.java 文 件<br />

package zyf.EX_Ctrl_3_B;<br />

import android.app.Activity;<br />

import android.os.Bundle;<br />

import android.widget.TextView;<br />

import android.widget.Toast;<br />

public class EX_Ctrl_3_B extends Activity {<br />

}<br />

/** Called when the activity is first created. */<br />

@Override<br />

public void onCreate(Bundle savedInstanceState) {<br />

super.onCreate(savedInstanceState);<br />

}<br />

3<br />

/* 设 置 主 屏 布 局 */<br />

setContentView(R.layout.main);<br />

/* 创 建 新 Toast 对 象 */<br />

Toast showImageToast = new Toast(this<br />

this);<br />

/* 新 建 TextView 对 象 */<br />

TextView text=new<br />

TextView(this<br />

this);<br />

/* 设 置 TextView 内 容 */<br />

text.setText(" 显 示 在 Toast 中 的 TextView");<br />

/* 设 置 Toast 上 的 View--(TextView) */<br />

showImageToast.setView(text);<br />

/* 设 置 Toast 显 示 时 间 */<br />

showImageToast.setDuration(Toast.LENGTH_LONG);<br />

/* 显 示 Toast */<br />

showImageToast.show();<br />

结 果<br />

15

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!