Android笔记之——消息Toast
2024-08-28 12:07:09
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>
最新文章
- Linux Shell 截取字符串
- 关于oracle中in和exists的区别
- 可在广域网部署运行的QQ高仿版 -- GG叽叽(源码)
- 字符串驱动技术—— MethodAddress , MethodName , ObjectInvoke
- linux 查看所有用户
- mac os安装基本的install环境,命令行安装软件
- 13.首次安装CY7C68013A驱动失败记(结果竟然是这样)
- codeforces 659A Round House
- 【转】【cocos2d-x教程】如何使用WebSocket
- c# label的内容显示不全
- win7 64位 VS2010调试提示“ORA-12154: TNS: 无法解析指定的连接标识符”的解决方法
- 获取证书以用于 Windows Azure 网站 (WAWS)
- 详解功能版本管理之使用eoLinker
- 《android开发艺术探索》读书笔记(八)--WindowManager
- svn提交出现错误 svn: Working copy &#39;D:\...&#39;locked.
- IP-v4&;IP-v6
- 微信公众号Java接入demo
- 下划线字符串camel
- Java零基础教程(二)基础语法
- 第6月第17天 CGAffineTransformMake(a,b,c,d,tx,ty) 矩阵运算的原理
热门文章
- 使用Visual Studio调试用户模式进程(Debugging a User-Mode Process Using Visual Studio)
- C++ vector erase函数的使用注意事项
- CentOS7:配置SVN服务器
- C#预编译
- ESET使用
- How to Take Control of Your Line Height in Outlook.com
- Java Docs
- jQuery Validate + Ckeditor 驗證 textarea 解決方式
- html5的FormData对象和input的file属性以及window.URL.createObjectURL( ) 方法(转载)
- WS+MQ+WCF+EF(Code First)