Activity:

 package com.example.editortoast;

 import android.app.Activity;
import android.os.Bundle;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.TextView;
import android.widget.Toast; public class MainActivity extends Activity { @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
findViewById(R.id.bt).setOnClickListener(new OnClickListener() { @Override
public void onClick(View v) {
toastShow();
}
});
} private void toastShow() {
LayoutInflater inflater = LayoutInflater.from(getApplicationContext());
View view = inflater.inflate(R.layout.item_toast, null);
TextView textView1 = (TextView) view.findViewById(R.id.TextView_1);
textView1.setText("Toast1"); Toast toast = new Toast(getApplicationContext());
toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
toast.setDuration(0);
toast.setView(view);
toast.show();
}
}

activity_main.xml:

 <RelativeLayout 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"
tools:context="com.example.editortoast.MainActivity" > <Button
android:id="@+id/bt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="点击" /> </RelativeLayout>

item_toast.xml:

 <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" > <ImageView
android:id="@+id/image"
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_centerVertical="true"
android:src="@drawable/ic_launcher" /> <TextView
android:id="@+id/TextView_1" android:textSize="30sp"
android:textColor="@android:color/holo_red_light"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toRightOf="@id/image" /> </RelativeLayout>

自定义Toast的显示效果的更多相关文章

  1. 023 Android 自定义Toast控件

    1.Toast自定义控件工具类 package com.example.administrator.test62360safeguard.Utils; import android.content.C ...

  2. Android带图片的Toast(自定义Toast)

    使用Android默认的Toast Toast简介: Toast是一个简单的消息显示框,能够短暂的出现在屏幕的某个位置,显示提示消息. 默认的位置是屏幕的下方正中,一般Toast的使用如下: Toas ...

  3. 自定义Toast和RatingBar的简单用例

    Toast是一个包含用户点击消息.Toast类会帮助你创建和显示这些.Android中的Toast是一种简易的消息提示框. 当视图显示给用户,在应用程序中显示为浮动 向右划动五角星增加 单击按钮显示自 ...

  4. 朝花夕拾-android 自定义toast

    在一个只有你而且还未知的世界中,不去探索未知,死守一处,你到底在守什么呢? 作为一个目前的android程序员,可能过去写着delphi的代码,可能未来回去搭建服务器.不管怎样,你现在是一名安卓程序员 ...

  5. Android 自定义Toast

    自定义Toast 其实就是自定义布局文件 感觉利用Dialog或者PopupWindow做也差不多 上图上代码 public class MainActivity extends Activity { ...

  6. Android Toast 设置到屏幕中间,自定义Toast的实现方法,及其说明

    http://blog.csdn.net/wangfayinn/article/details/8065763 Android Toast用于在手机屏幕上向用户显示一条信息,一段时间后信息会自动消失. ...

  7. Android开发必知--自定义Toast提示

    开发过Android的童鞋都会遇到一个问题,就是在打印Toast提示时,如果短时间内触发多个提示,就会造成Toast不停的重复出现,直到被触发的Toast全部显示完为止.这虽然不是什么大毛病,但在用户 ...

  8. android 自定义Toast显示风格

    1.创建一个自己想要显示Toast风格的XML如下代码(toast_xml.xml): <?xml version="1.0" encoding="utf-8&qu ...

  9. 自定义Toast

    简易自定义Toast public class MainActivity extends ListActivity );//边角         gradientDrawable.setGradien ...

随机推荐

  1. C#中如何设置窗体的默认按钮和取消按钮

    可以直接在窗体的AcceptButton和CancelButton中设置相应的按钮. 也可以在后头通过代码设置: this.AcceptButton = (IButtonControl)btnSave ...

  2. Spring Data Jpa 规范接口表

      Keyword Sample JPQL snippet And findByLastnameAndFirstname … where x.lastname = ?1 and x.firstname ...

  3. c# MessageBox使用

    最近一直用到winform的MessageBox,感觉还是很混乱.刚好在网上发现xuenzhen的博客,特此借鉴记录一些东西. 下面的MessageBox的九中用法,来自xuenzhen的博客:htt ...

  4. 十步让你调试mvc源码

    1.下载 mvc 当前版本的源码,地址:http://aspnetwebstack.codeplex.com/SourceControl/latest 2.编译源码,参考:http://www.cnb ...

  5. excel读取指定行

    任意单元格输入=OFFSET($A$1,(ROW(A1)-1)*20,0) 往下拉就出来了

  6. HDU1232畅通工程

    http://acm.split.hdu.edu.cn/showproblem.php?pid=1232 #include<stdio.h> #include<string.h> ...

  7. 我的Python基础笔记

    Python是从刚开始参加工作,就有听各方面的测试大牛推崇,但是刚开始做测试时还是把基础的测试方法放在第一位来学习的,直到半年多以后才开始接触Python. 我的Python基础主要是以廖雪峰老师的在 ...

  8. 2016阿里巴巴校招offer面经

    前段时间参加阿里巴巴校招,非常荣幸,很快就拿到了offer,经历了三轮技术面试和一轮hr面,面试官们都非常nice,在此感谢一下各位面试官,你们辛苦了,百忙之中抽时间面试!为了帮助更多人想进阿里巴巴的 ...

  9. 转载收藏- (TTL与CMOS)电路常识性概念

    原帖:http://blog.sina.com.cn/s/blog_48c0c0190101bbth.html

  10. opencv 连通域需要的函数解析

    OpenCV支持大量的轮廓.边缘.边界的相关函数,相应的函数有moments.HuMoments.findContours.drawContours.approxPolyDP.arcLength.bo ...