java:

package com.example.myapplication;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Toast; public class MainActivity extends AppCompatActivity { @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void test1 (View view){
// Toast.makeText(this,"hello test",Toast.LENGTH_SHORT).show();
Toast.makeText(this.getApplicationContext(),"hello test",Toast.LENGTH_SHORT).show();
//第一个参数
/*
* this --> 当前的activity对象--> context
* this.getApplicationContext()--> context
* */
} }
XML:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.myapplication.MainActivity"> <TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!" /> <Button
android:text="Button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/textView"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginLeft="49dp"
android:layout_marginStart="49dp"
android:layout_marginTop="117dp"
android:id="@+id/button"
android:onClick="test1"
/>
</RelativeLayout>

Android笔记之——消息Toast的更多相关文章

  1. Android源码解析——Toast

    简介 Toast是一种向用户快速展示少量信息的视图.当它显示时,它会浮在整个应用层的上面,并且不会获取到焦点.它的设计思想是能够向用户展示些信息,但又能尽量不显得唐突.本篇我们来研读一下Toast的源 ...

  2. Android笔记——Android中数据的存储方式(二)

    我们在实际开发中,有的时候需要储存或者备份比较复杂的数据.这些数据的特点是,内容多.结构大,比如短信备份等.我们知道SharedPreferences和Files(文本文件)储存这种数据会非常的没有效 ...

  3. 浅析Android中的消息机制(转)

    原博客地址:http://blog.csdn.net/liuhe688/article/details/6407225 在分析Android消息机制之前,我们先来看一段代码: public class ...

  4. Android核心分析 之十一Android GWES之消息系统

        Android GWES之Android消息系统                                                                        ...

  5. 浅析Android中的消息机制(转)

    在分析Android消息机制之前,我们先来看一段代码: public class MainActivity extends Activity implements View.OnClickListen ...

  6. Linux进程间通信IPC学习笔记之消息队列(SVR4)

    Linux进程间通信IPC学习笔记之消息队列(SVR4)

  7. Android笔记:触摸事件的分析与总结----TouchEvent处理机制

    原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 .作者信息和本声明.否则将追究法律责任.http://glblong.blog.51cto.com/3058613/1559320   ...

  8. 浅析Android中的消息机制-解决:Only the original thread that created a view hierarchy can touch its views.

    在分析Android消息机制之前,我们先来看一段代码: public class MainActivity extends Activity implements View.OnClickListen ...

  9. 浅析Android中的消息机制

    在分析Android消息机制之前,我们先来看一段代码: public class MainActivity extends Activity implements View.OnClickListen ...

随机推荐

  1. mysql解决Value ‘0000-00-00 00:00:00’ can not be represented as java.sql.Timestamp

    同步发布:http://www.yuanrengu.com/index.php/mysqlsolvetimestamp.html 在使用mysql时,如果数据库中的字段类型是timestamp,默认为 ...

  2. Spring AOP 由浅入深

    (分析基于Spring的版本:version = 4.1.6.RELEASE) Spring AOP工厂: org.springframework.aop.framework.DefaultAopPr ...

  3. 用exp导数据时遇到oracle 1455的错误

    exp scott/scott@orcl file=d:\impbak\20161214.dmp owner=scott TRIGGERS=n INDEXES=n STATISTICS=none(ow ...

  4. C#动态编译代码,执行一个代码片段,或者从指定文件中加载某个接口的实现类

    在项目进行中有时候会需要配置一些复杂的表达式,在程序运行的时候执行表达式,根据结果执行相应的操作,简单写了一个类Expression,利用.net的动态编译技术实现,代码如下: public clas ...

  5. 使用delphi+intraweb进行微信开发2—intraweb以.net方式发布(以asp.net mvc4模式部署)在IIS(.net虚拟主机)上

    在第一讲使用delphi+intraweb进行微信开发1--微信平台接入中我们编写了一个简单的微信接口程序,这个程序我是用Stand Alone Server / Service 方式编译的程序,并且 ...

  6. dos命令 禁用网络链接

    获取所有的网络链接接口: C:\Users\Chris.JENNEY>netsh interface show interface Admin State State  Type Interfa ...

  7. android需知小细节

    1. 布局文件命名不能包含大写字母,特殊字符.MyImageView.xml错误. 2. simpleAdapter适配器参数的含义:  3. gridview gridview的三个重要的属性: 4 ...

  8. Mutex

    #include "stdafx.h" #include <string> #include <iostream> #include <Windows ...

  9. sm4加密 解密(oc)

    前几天项目用到sm4加密解密,加密为十六进制字符串,再将十六进制字符串解密.网上百度了下,sm4是密钥长度和加密明文加密密文都为16个字节十六进制数据,网上的sm4 c语言算法很容易搜到,笔者刚开始没 ...

  10. top 10 tipis on Logging in Java- Tutorial (翻译)

    开篇废话,就记得出国之前有一回腾讯面试,面试官说既然你都快要出国了,英语肯定挺不错的,那为什么不去翻译一些国外好的文章呢,我希望找一个能主动学习的人,一直受教.目前在实习,需要做大数据相关方向,都是挺 ...