• linkedu视频
  • 平面设计
  • 电脑入门
  • 操作系统
  • 办公应用
  • 电脑硬件
  • 动画设计
  • 3D设计
  • 网页设计
  • CAD设计
  • 影音处理
  • 数据库
  • 程序设计
  • 认证考试
  • 信息管理
  • 信息安全
菜单
linkedu.com
  • 网页制作
  • 数据库
  • 程序设计
  • 操作系统
  • CMS教程
  • 游戏攻略
  • 脚本语言
  • 平面设计
  • 软件教程
  • 网络安全
  • 电脑知识
  • 服务器
  • 视频教程
  • JavaScript
  • ASP.NET
  • PHP
  • 正则表达式
  • AJAX
  • JSP
  • ASP
  • Flex
  • XML
  • 编程技巧
  • Android
  • swift
  • C#教程
  • vb
  • vb.net
  • C语言
  • Java
  • Delphi
  • 易语言
  • vc/mfc
  • 嵌入式开发
  • 游戏开发
  • ios
  • 编程问答
  • 汇编语言
  • 微信小程序
  • 数据结构
  • OpenGL
  • 架构设计
  • qt
  • 微信公众号
您的位置:首页 > 程序设计 >Android > 自定义Toast的显示位置和显示内容,自定义toast

自定义Toast的显示位置和显示内容,自定义toast

作者:网友 字体:[增加 减小] 来源:互联网 时间:2017-05-26

网友通过本文主要向大家介绍了自定义toast位置,自定义toast,android 自定义toast,安卓自定义toast,android中自定义toast等相关知识,希望对您有所帮助,也希望大家支持linkedu.com www.linkedu.com

自定义Toast的显示位置和显示内容,自定义toast


 1 <?xml version="1.0" encoding="utf-8"?>
 2 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 3     xmlns:app="http://schemas.android.com/apk/res-auto"
 4     xmlns:tools="http://schemas.android.com/tools"
 5     android:layout_width="match_parent"
 6     android:layout_height="match_parent"
 7     android:orientation="vertical"
 8     tools:context="com.example.leeson7_1_id19.MainActivity">
 9 
10     <Button
11         android:onClick="toast_1"
12         android:layout_width="match_parent"
13         android:layout_height="wrap_content"
14         android:text="普通的toast" />
15     <Button
16         android:onClick="toast_2"
17         android:layout_width="match_parent"
18         android:layout_height="wrap_content"
19         android:text="自定义的toast" />
20     <Button
21         android:onClick="toast_3"
22         android:layout_width="match_parent"
23         android:layout_height="wrap_content"
24         android:text="自定义位置的toast" />
25 </LinearLayout>
 1 <?xml version="1.0" encoding="utf-8"?>
 2 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 3     android:layout_width="match_parent"
 4     android:layout_height="match_parent"
 5     android:orientation="vertical">
 6 
 7     <TextView
 8         android:layout_width="match_parent"
 9         android:layout_height="wrap_content"
10         android:text="自定义位置文本"
11         android:gravity="center"
12         android:background="#ff0000"
13         android:padding="5dp"
14         android:textSize="18sp"/>
15 
16 
17 </LinearLayout>
 1 package com.example.leeson7_1_id19;
 2 
 3 import android.os.Bundle;
 4 import android.support.v7.app.AppCompatActivity;
 5 import android.view.Gravity;
 6 import android.view.View;
 7 import android.widget.ImageView;
 8 import android.widget.Toast;
 9 
10 public class MainActivity extends AppCompatActivity {
11 
12     @Override
13     protected void onCreate(Bundle savedInstanceState) {
14         super.onCreate(savedInstanceState);
15         setContentView(R.layout.activity_main);
16     }
17 
18     public void toast_1(View V){
19         // 设置土司显示的内容和时长并显示出来
20         Toast.makeText(this,"我是一个普通的toast",Toast.LENGTH_SHORT).show();
21     }
22     public void toast_2(View V){
23         // 自定义土司
24         // 创建土司
25         Toast toast = new Toast(this);
26         // 设置土司显示的时间长短
27         toast.setDuration(Toast.LENGTH_SHORT);
28         // 创建ImageView
29         ImageView img = new ImageView(this);
30         // 设置图片的资源路径
31         img.setImageResource(R.mipmap.ic_launcher);
32         // 设置土司的视图图片
33         toast.setView(img);
34         // 显示土司
35         toast.show();
36     }
37     public void toast_3(View V){
38         // 自定义土司显示位置
39         // 创建土司
40         Toast toast = new Toast(this);
41         // 找到toast布局的位置
42         View layout = View.inflate(this,R.layout.toast,null);
43         // 设置toast文本,把设置好的布局传进来
44         toast.setView(layout);
45         // 设置土司显示在屏幕的位置
46         toast.setGravity(Gravity.FILL_HORIZONTAL|Gravity.TOP,0,70);
47         // 显示土司
48         toast.show();
49     }
50 }

 

分享到:QQ空间新浪微博腾讯微博微信百度贴吧QQ好友复制网址打印

您可能想查找下面的文章:

  • 自定义Toast的显示位置和显示内容,自定义toast

相关文章

  • 2017-05-26[android] 手机卫士界面切换动画,android卫士
  • 2017-05-26自定义Dialog,android自定义dialog
  • 2017-05-222.6.0 其他几种常用对话框基本使用
  • 2017-05-26Android提权漏洞CVE-2014-7920&amp;CVE-2014-7921分析
  • 2017-05-26安卓下如何使用JUnit进行软件测试,安卓junit
  • 2017-05-26显示当前光照强度,当前光照强度
  • 2017-05-26MaterialRefreshLayout,swiperefreshlayout
  • 2017-07-22Android深入四大组件(四)广播的注册、发送和接收过程
  • 2017-05-26zoom动画,实现图片点击预览效果,zoom预览
  • 2017-05-26继承ViewGroup学习onMeasure()和onLayout()方法,viewgrouponmeasure

文章分类

  • JavaScript
  • ASP.NET
  • PHP
  • 正则表达式
  • AJAX
  • JSP
  • ASP
  • Flex
  • XML
  • 编程技巧
  • Android
  • swift
  • C#教程
  • vb
  • vb.net
  • C语言
  • Java
  • Delphi
  • 易语言
  • vc/mfc
  • 嵌入式开发
  • 游戏开发
  • ios
  • 编程问答
  • 汇编语言
  • 微信小程序
  • 数据结构
  • OpenGL
  • 架构设计
  • qt
  • 微信公众号

最近更新的内容

    • Android Studio 错误解决办法
    • android 公司app升级UI总结分析
    • 整理几篇比较好的AndroidUI动画开发文章,几篇androidui
    • Android中BroadcastReceiver的两种注册方式(静态和动态)详解,broadcastreceiver
    • OpenDigg安卓开源项目月报201704,opendigg安卓201704
    • Android UI相关开源项目库汇总,android开源项目
    • 我的android学习经历2,android学习经历2
    • Android环境搭建和编写helloworld,androidhelloworld
    • Android入门(九)文件存储与SharedPreferences存储,
    • android测试工具MonkeyRunner--google官网翻译

关于我们 - 联系我们 - 免责声明 - 网站地图

©2020-2025 All Rights Reserved. linkedu.com 版权所有