android 吐丝的五种不同显示形式

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"tools:context=".MainActivity" ><Buttonandroid:layout_width="fill_parent"android:layout_height="wrap_content"android:text="系统默认的吐丝"android:id="@+id/sys_btn" /><Buttonandroid:layout_width="fill_parent"android:layout_height="wrap_content"android:text="自定义位置的吐丝"android:id="@+id/define_location_btn" /><Buttonandroid:layout_width="fill_parent"android:layout_height="wrap_content"android:text="带图片的吐丝"android:id="@+id/define_img_btn" /><Buttonandroid:layout_width="fill_parent"android:layout_height="wrap_content"android:text="完全自定义的吐丝"android:id="@+id/define_btn" /><Buttonandroid:layout_width="fill_parent"android:layout_height="wrap_content"android:text="长时间显示的吐丝"android:id="@+id/long_btn" /></LinearLayout>
自定义吐丝样式:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"android:id="@+id/toast_layout"android:layout_width="200dip"android:layout_height="fill_parent"android:background="#111111"android:orientation="vertical" ><TextViewandroid:id="@+id/txt_Title"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_gravity="center|top"android:text="自定义标签"android:textColor="#ffffff"android:textSize="20dip" ></TextView><LinearLayoutandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:background="#999999"android:orientation="horizontal" ><ImageViewandroid:id="@+id/image_toast"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_marginRight="10dip"android:src="@drawable/ic_launcher" ></ImageView><TextViewandroid:id="@+id/txt_context"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_gravity="center|right"android:text="这是个小机器人"android:textColor="#ffffff"android:textSize="15dip" ></TextView></LinearLayout></LinearLayout>
MainActivity代码:
package com.ljgui.toast;import android.app.Activity;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.os.Bundle;
import android.view.Gravity;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.Toast;public class MainActivity extends Activity implements OnClickListener {private Button btn1;private Button btn2;private Button btn3;private Button btn4;private Button btn5;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);btn1 = (Button) findViewById(R.id.sys_btn);btn2 = (Button) findViewById(R.id.define_location_btn);btn3 = (Button) findViewById(R.id.define_img_btn);btn4 = (Button) findViewById(R.id.define_btn);btn5 = (Button) findViewById(R.id.long_btn);btn1.setOnClickListener(this);btn2.setOnClickListener(this);btn3.setOnClickListener(this);btn4.setOnClickListener(this);btn5.setOnClickListener(this);}@Overridepublic void onClick(View v) {switch (v.getId()) {case R.id.sys_btn:Toast.makeText(MainActivity.this, "这是系统默认的吐丝", 0).show();break;case R.id.define_location_btn:Toast t = Toast.makeText(MainActivity.this, "这是自定义位置的吐丝", 0);t.setGravity(Gravity.CENTER, 0, 0);t.show();break;case R.id.define_img_btn:Toast t2 = Toast.makeText(MainActivity.this, "这是带图片的的吐丝", 0);t2.setGravity(Gravity.CENTER, 0, 0);LinearLayout ll = (LinearLayout) t2.getView();ImageView img = new ImageView(MainActivity.this);img.setImageResource(R.drawable.ic_launcher);ll.addView(img, 0);t2.show();break;case R.id.define_btn:View view = getLayoutInflater().inflate(R.layout.userdefinedtoast,(GridView) findViewById(R.id.toast_layout));Toast t4 = new Toast(getApplicationContext());t4.setDuration(0);t4.setView(view);t4.show();break;case R.id.long_btn:View view5 = getLayoutInflater().inflate(R.layout.userdefinedtoast,(GridView) findViewById(R.id.toast_layout));Builder b = new AlertDialog.Builder(MainActivity.this);b.setView(view5);b.create();b.show();break;}}
}
运行结果:
1系统默认吐丝效果:
  
2.自定义吐丝位置:
3.带图片的吐丝:
4.完全自定义吐丝样式:
  
5.长时间吐丝(ps:这个实现时并没有用到Toast类,但好多人也说这是吐丝的一种,所以就贴上了)

android吐丝的五种不同的显示相关推荐

  1. android自定义dialog开源库,android-dialog: 此框架提供五种对话框的显示,并支持对话框的扩展,目的是为了提供对话框的统一管理,并提供对话框显示的公共接口。...

    android-dialog 此框架提供七种对话框的显示,并支持对话框的扩展,目的是为了提供对话框的统一管理,并提供对话框显示的公共接口. LoadingDialog:正在加载对话框 MessageD ...

  2. Android数据存储五种方式总结

    1 使用SharedPreferences存储数据     2 文件存储数据       3 SQLite数据库存储数据 4 使用ContentProvider存储数据 5 网络存储数据 下面详细讲解 ...

  3. [Android Studio]掌握Android Studio的五种常见控件和五种常见布局

    目录 一.View和ViewGroup 二.Android的五种常见控件 2.1 文本控件 2.1.1 TextView 2.1.2 EditText 2.2 按钮控件 2.2.1 Button 2. ...

  4. Android中常见五种布局管理器——RelativeLayout、LinearLayout、FrameLayout、TableLayout、GridLayout

    目录 布局管理器 RelativeLayout 常见属性 Relative的实践操作(实现软件更新界面) LinearLayout 常见属性 LinearLayout的实践操作(模范登录以及微信底部) ...

  5. android数据的五种存储方式

    Android提供了5种方式存储数据 1 使用SharedPreferences存储数据 它的本质是基于XML文件存储key-value键值对数据,通常用来存储一些简单的配置信息. 其存储位置在/da ...

  6. android 投影ios,五种良心屏幕投影软件,将Android和iOS投影到大屏幕

    随着智能手机的普及,越来越多的人习惯于在手机上观看照片和视频,在会议中显示资料或玩手机游戏. 在玩手机游戏时,小于计算机大屏幕的视野已成为最大的限制,因此许选择使用投影软件将手机屏幕投射到计算机或电视 ...

  7. android 按钮 onClick 五种事件写法

    ```//第一种.匿名内部类: btn_back.setOnClickListener(new OnClickListener() {@Overridepublic void onClick(View ...

  8. Android常用的五种布局

    开发工具与关键技术:Android studio64, Android 1.FrameLayout(帧布局)是最简单的布局方式,放置的控件都只能罗列到左上角,控件会有重叠,不能进行复杂的布局. 2.L ...

  9. 小巫跟你聊聊《琅琊榜》,android屏幕适配五种方式

    之后我就带着好奇心完完整整把它看了一遍,先说一下我自己的感受吧,一个字"好看",应该算是近些年良心的国产剧了,无论是从故事情节.演员演技.剧中布景.特效.服装都能称得上精良,反正我 ...

最新文章

  1. 比特币核心概念及算法
  2. 存储过程debug值not a variable_C语言变量的存储类别
  3. 初步了解Windows应用程序内存结构 - 使用VMMAP工具
  4. 使用redis实现异步消息队列
  5. Python中yield返回生成器的详细方法
  6. Linux压缩包和用户管理及开关机指令
  7. 前天看了sigmastar新品发布,双核,1.2GHZ,真香!更多你想要了解的SSD201/202技术问题,看过来!启明云端MM帮你整理了!拿走不谢
  8. boost::shared_lock相关的测试程序
  9. python爬虫自动化采集集群_python爬虫_校园网自动重连脚本
  10. iOS版微信跟上了!已支持改微信号,修改后好友不会收到提醒
  11. 【侯捷】C++内存管理机制
  12. 单摆的动力学建模以及matlab仿真(牛顿法和拉格朗日方程法)
  13. 用CSS+HTML代码制作的3D动态旋转相册
  14. 中国式“高定美学”燃爆广州秀场!「琢我」之气场与「莲玉芳华」之优雅
  15. 五、DML(数据操纵语句)
  16. Flutter调用阿里云识别银行卡
  17. Java实现人民币大小写转换
  18. 在腾讯实习的五个月的一些思考与收获
  19. C++RTSP服务端(附源码)
  20. 投票 | 给烤仔一个和星球君一起胖的机会吧

热门文章

  1. 车载总线数据库转换工具 - INTEWORK-VDC
  2. android 跳动频谱 播放器(类似千千静听)
  3. sqlmap学习思路笔记
  4. 《Photoshop+Lightroom数码摄影后期处理经典教程》目录—导读
  5. 实用贴,HDTV的4个基本元素
  6. Word无法启动转换器RECOVR32.CNV解决方法
  7. 如何让中小学生参加机器人竞赛
  8. 怎么用c语言写情书代码,用C语言写的情书
  9. 自定义控件 imageview 双击显示红色边框
  10. MATLAB中判断一个矩阵或者数字是否是复数