/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. C++ 虚函数畅谈

    0x01:前言 虚函数是C++里最重要的概念之一,并且是判定C++是否入门的一个热门问题.今天这篇文章简单谈谈虚函数. 0x02:虚函数简介 虚函数可以被子类实现函数所覆盖. virtual是关键字, ...

  2. CSS控制"标题前增加小图标或编号"

    ---题目前加图片--- p:before { content:url(xxx/xx.png); }//所有p的最前都有一个图标 p.a:after { content:url(xxx/xx.png) ...

  3. jade编译乱码问题

    加上: meta(http-equiv="Content-Type",content="text/html; charset=utf-8")

  4. window平台安装MongoDB

    官网:www.mongodb.org 安装-->设置环境变量-->启动 1.下载: 根据系统下载 32 位或 64 位的 .msi 文件,下载后双击该文件,按提示安装即可, 2.设置安装目 ...

  5. SQL集合函数中利用case when then 技巧

    我们都知道SQL中适用case when then来转化数据库中的信息 比如  select (case sex when 0 then '男' else '女' end) AS sex  from ...

  6. NSNotificationCenter带参

    (1)post Notification类 [[NSNotificationCenter defaultCenter] postNotificationName:CRMPerformanceNewCe ...

  7. hadoop MapReduce 工作机制

    摸索了将近一个月的hadoop , 在centos上配了一个伪分布式的环境,又折腾了一把hadoop eclipse plugin,最后终于实现了在windows上编写MapReduce程序,在cen ...

  8. iOS 拉伸图片

    UIEdgeInsets:四个参数,会填入上左下右几个值,这几个值,代表着距离边界的这几个点描绘的区域,是不会拉伸的.所以,到时候,计算清楚这几个值就可以了.

  9. 【转】使用git、git-flow与gitlab工作

    转自:http://www.tuicool.com/articles/BZJRj2 使用git.git-flow与gitlab工作 时间 2013-11-02 00:40:39  Axb的自我修养 原 ...

  10. java 获取请求客户端的真实IP地址

    转载自:http://leiyongping88.iteye.com/blog/1545930 用request.getRemoteAddr();方法获取的IP地址是:127.0.0.1或192.16 ...