博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
4.3给圣诞老人的信息—Toast对象的使用
阅读量:6924 次
发布时间:2019-06-27

本文共 1252 字,大约阅读时间需要 4 分钟。

4.3给圣诞老人的信息—Toast对象的使用

目录

 

目标:使用Toast弹出消息.

方法:构造一个Toast对象,调用对象的show()方法

代码:

package edu.cquptzx.UseToast;

 

import android.app.Activity;

import android.os.Bundle;

import android.text.Editable;

import android.view.View;

import android.view.View.OnClickListener;

import android.widget.Button;

import android.widget.EditText;

import android.widget.Toast;

 

publicclass UseToastActivity extends Activity {

    private Button btn;

    private EditText et;

    /** Called when the activity is first created. */

    publicvoid onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        setContentView(R.layout.main);

       

        // Find the objects by IDs

        btn = (Button) findViewById(R.id.button);

        et = (EditText) findViewById(R.id.editText);

      

        // add an listener to tha SEND BUTTON.

        btn.setOnClickListener(new OnClickListener()

        {

           publicvoid onClick(View v)

           {

              //Get the text which the user have input .

              /* 方案二:使用Editable

               * 特点,文字获取后可以很方便的进行截取,插入,等操作. */

              //Editable str;

              //str = et.getText();

             

              /* 方案一:使用String

               * 特点,文字固定,编辑不方便. */

              String str = null;

              str = et.getText().toString();

             

              Toast.makeText(getBaseContext(),

                     "Your wish: \n  \" " + str.toString() + " \" \n has been send to  Santa Claus.",

                     Toast.LENGTH_LONG)

                     .show();

           }      

        });

    }

}

效果:

更多详细用法:

 

 

For more questions , contacts me by :

 or  

 

 

转载地址:http://shkjl.baihongyu.com/

你可能感兴趣的文章
1.2关系数据库
查看>>
SpringCloud
查看>>
RHEL主机安全检查机制: TCP Wrappers、Xinetd
查看>>
泛型编程之类模板
查看>>
salt安装
查看>>
linux运维基础1
查看>>
Hyper-V Server虚拟机移动性
查看>>
Visual Studio 2014 预览版 CTP3 发布了!可以下载
查看>>
protoc 在linux下的安装
查看>>
jq上百个input 做提交不能为空的验证
查看>>
网络篇
查看>>
全面详解Linux日志管理技巧
查看>>
翻译连载 | 第 11 章:融会贯通 -《JavaScript轻量级函数式编程》 |《你不知道的JS》姊妹篇...
查看>>
去中心化访问HTTP服务集群
查看>>
C语言switch语句的用法详解
查看>>
Linux系统和用户界面 中英文语言修改
查看>>
ELK(ElasticSearch, Logstash, Kibana)搭建实时日志分析平台
查看>>
centos6.9 上docker 的安装 及启动 和运行状态查看
查看>>
Linux安装类型和方法
查看>>
Java面试宝典(2)Java基础部分
查看>>