/Users/alamps/AndroidStudioProjects/demo16Toast/demo16Toast/src/main/res/layout/activity_main.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context=".MainActivity"> <Button android:id="@+id/_shortShow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Short Toast" /> <Button android:id="@+id/_longShow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Long Toast" /> <Button android:id="@+id/_customShow"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="customShow Toast" /> </LinearLayout>
================
/Users/alamps/AndroidStudioProjects/demo16Toast/demo16Toast/src/main/java/com/example/demo16toast/MainActivity.java package com.example.demo16toast; import android.os.Bundle;
import android.app.Activity;
import android.view.Gravity;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.Toast; public class MainActivity extends Activity {
private Button shortShow;
private Button longShow;
private Button customShow; @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); this.shortShow = (Button)super.findViewById(R.id._shortShow);
this.longShow = (Button)super.findViewById(R.id._longShow);
this.customShow = (Button)super.findViewById(R.id._customShow); this.shortShow.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Toast.makeText(MainActivity.this,"Short Toast show ",Toast.LENGTH_SHORT).show(); }
}); this.longShow.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Toast.makeText(MainActivity.this,"Long Toast Show ",Toast.LENGTH_LONG).show();
}
}); this.customShow.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Toast customToast= Toast.makeText(MainActivity.this,"Custom Toast show ",Toast.LENGTH_LONG); customToast.setGravity(Gravity.CENTER,,); LinearLayout customToastView =(LinearLayout)customToast.getView();
ImageView customImageView= new ImageView(MainActivity.this);
customImageView.setImageResource(R.drawable.ic_launcher);
customToastView.addView(customImageView,);//在文字上方填加图片View
customToast.show();
}
}); } @Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
} }

demo16Toast的更多相关文章

随机推荐

  1. jQuery.mobile.activePage获取当点活动的page

    <!doctype html> <html lang="en"> <head> <meta charset="utf-8&quo ...

  2. Redis学习笔记--五种数据类型的使用场景

    String 1.String 常用命令: 除了get.set.incr.decr mget等操作外,Redis还提供了下面一些操作: 获取字符串长度 往字符串append内容 设置和获取字符串的某一 ...

  3. Intersection of Two Linked Lists | LeetCode

    利用两个栈,然后分别存储每一个链表. 继而,相继pop相同的节点. 有些细节需要注意,请看最后的返回值是如何处理的. /** * Definition for singly-linked list. ...

  4. Selenium2学习-009-WebUI自动化实战实例-007-Selenium 8种元素定位实战实例源代码(百度首页搜索录入框及登录链接)

    此 文主要讲述用 Java 编写 Selenium 自动化测试脚本编写过程中,通过 ID.name.xpath.cssSelector.linkText.className.partialLinkTe ...

  5. 解决调用context.Session["NAME"]时总出现Object reference not set to an instance of an object.异常的方法

    if (context.Session != null) { }

  6. js判断手机访问web网站跳转到手机版

    第一种:直接JS脚本 <script type="text/javascript">try {var urlhash = window.location.hash;if ...

  7. flex布局中flex-basis|flex-grow|flex-shrink

    flex布局中flex-basis|flex-grow|flex-shrink 整个才是正确的算法 flex-basis(基准值) 可以设置flex布局中容器的宽度,如果同时存在width属性,将把它 ...

  8. Linux就这个范儿 第15章 七种武器 linux 同步IO: sync、fsync与fdatasync Linux中的内存大页面huge page/large page David Cutler Linux读写内存数据的三种方式

    Linux就这个范儿 第15章 七种武器  linux 同步IO: sync.fsync与fdatasync   Linux中的内存大页面huge page/large page  David Cut ...

  9. Ubuntu 上安装 Freemind 并支持中文

    Ubuntu 上安装 Freemind 并支持中文 JAVA 运行时 Freemind 是一个使用 Java 编写的思维导图工具,在安装时,需要到 Java 运行时(使用 OpenJRE 或 Orac ...

  10. andriod网址

    http://www.runoob.com/w3cnote/android-tutorial-end.html  入门教程 长青说安卓