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>

最新文章

  1. Linux Shell 截取字符串
  2. 关于oracle中in和exists的区别
  3. 可在广域网部署运行的QQ高仿版 -- GG叽叽(源码)
  4. 字符串驱动技术—— MethodAddress , MethodName , ObjectInvoke
  5. linux 查看所有用户
  6. mac os安装基本的install环境,命令行安装软件
  7. 13.首次安装CY7C68013A驱动失败记(结果竟然是这样)
  8. codeforces 659A Round House
  9. 【转】【cocos2d-x教程】如何使用WebSocket
  10. c# label的内容显示不全
  11. win7 64位 VS2010调试提示“ORA-12154: TNS: 无法解析指定的连接标识符”的解决方法
  12. 获取证书以用于 Windows Azure 网站 (WAWS)
  13. 详解功能版本管理之使用eoLinker
  14. 《android开发艺术探索》读书笔记(八)--WindowManager
  15. svn提交出现错误 svn: Working copy &#39;D:\...&#39;locked.
  16. IP-v4&amp;IP-v6
  17. 微信公众号Java接入demo
  18. 下划线字符串camel
  19. Java零基础教程(二)基础语法
  20. 第6月第17天 CGAffineTransformMake(a,b,c,d,tx,ty) 矩阵运算的原理

热门文章

  1. 使用Visual Studio调试用户模式进程(Debugging a User-Mode Process Using Visual Studio)
  2. C++ vector erase函数的使用注意事项
  3. CentOS7:配置SVN服务器
  4. C#预编译
  5. ESET使用
  6. How to Take Control of Your Line Height in Outlook.com
  7. Java Docs
  8. jQuery Validate + Ckeditor 驗證 textarea 解決方式
  9. html5的FormData对象和input的file属性以及window.URL.createObjectURL( ) 方法(转载)
  10. WS+MQ+WCF+EF(Code First)