自定义Toast的显示位置和显示内容
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.example.leeson7_1_id19.MainActivity"> <Button
android:onClick="toast_1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="普通的toast" />
<Button
android:onClick="toast_2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="自定义的toast" />
<Button
android:onClick="toast_3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="自定义位置的toast" />
</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"> <TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="自定义位置文本"
android:gravity="center"
android:background="#ff0000"
android:padding="5dp"
android:textSize="18sp"/> </LinearLayout>
package com.example.leeson7_1_id19; import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.Gravity;
import android.view.View;
import android.widget.ImageView;
import android.widget.Toast; public class MainActivity extends AppCompatActivity { @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
} public void toast_1(View V){
// 设置土司显示的内容和时长并显示出来
Toast.makeText(this,"我是一个普通的toast",Toast.LENGTH_SHORT).show();
}
public void toast_2(View V){
// 自定义土司
// 创建土司
Toast toast = new Toast(this);
// 设置土司显示的时间长短
toast.setDuration(Toast.LENGTH_SHORT);
// 创建ImageView
ImageView img = new ImageView(this);
// 设置图片的资源路径
img.setImageResource(R.mipmap.ic_launcher);
// 设置土司的视图图片
toast.setView(img);
// 显示土司
toast.show();
}
public void toast_3(View V){
// 自定义土司显示位置
// 创建土司
Toast toast = new Toast(this);
// 找到toast布局的位置
View layout = View.inflate(this,R.layout.toast,null);
// 设置toast文本,把设置好的布局传进来
toast.setView(layout);
// 设置土司显示在屏幕的位置
toast.setGravity(Gravity.FILL_HORIZONTAL|Gravity.TOP,0,70);
// 显示土司
toast.show();
}
}




自定义Toast的显示位置和显示内容的更多相关文章
- 自定义Toast样式-两行文本居中显示
toast可以设置自定义的view和显示位置.下面是一个简单的例子,复杂些的就是改变其布局文件就可以了. /** * @author BMR * @ClassName: ToastWithTwoTex ...
- Android PopupWindow显示位置和显示大小
watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQveGlhb3l1YW41MTE=/font/5a6L5L2T/fontsize/400/fill/I0JBQk ...
- Winform WPF 窗体显示位置
WinForm 窗体显示位置 窗体显示的位置首先由窗体的StartPosition决定,FormStartPosition这个枚举值由如下几种情况 // 摘要: // 窗体的位置由 System.Wi ...
- ToastUtil【简单的Toast封装类】【未自定义Toast的显示风格】
版权声明:本文为HaiyuKing原创文章,转载请注明出处! 前言 一个简单的Toast封装类. 效果图 API = 6.0 API = 4.4.2 代码分析 实现了不管我们触发多少次Toast调用, ...
- ToastCustomUtil【简单的Toast封装类】【自定义Toast的显示风格】
版权声明:本文为HaiyuKing原创文章,转载请注明出处! 前言 ToastUtil + ToastCustom结合.主要解决低版本机型上系统toast显示不好看的问题. 效果图 代码分析 在Toa ...
- android 自定义Toast显示风格
1.创建一个自己想要显示Toast风格的XML如下代码(toast_xml.xml): <?xml version="1.0" encoding="utf-8&qu ...
- 设置Toast显示位置
设置Toast显示位置 两个方法可以设置显示位置: 方法一:setGravity(int gravity, int xOffset, int yOffset)三个参数分别表示(起点位置,水平向右位移, ...
- 自定义Toast排队重复显示问题:
原文 http://blog.csdn.net/baiyuliang2013/article/details/38655495Toast是安卓系统中,用户误操作时或某功能执行完毕时,对用户的一种提示, ...
- 在ASP.NET MVC中使用Knockout实践07,自定义验证信息的位置与内容
在前两篇中,体验了Knockout的基本验证和自定义验证.本篇自定义验证信息的显示位置与内容. 自定义验证信息的显示位置 通常,Knockout的验证信息紧跟在input后面,通过validation ...
随机推荐
- Python return语句用法分析
return 语句 程序运行到所遇到的第一个return即返回(退出def块),不会再运行第二个return. 要返回两个数值,写成一行即可: def a(x,y): if x==y: return ...
- window.name应用于浏览器端数据存储
本代码简单地分享利用window.name实现浏览器端数据存储: 1.在同一个页面一个地方设置window.name = "abc",另外一个地方读取window.name,自然能 ...
- mac系统下查看端口占用情况
localhost:~ mhx$ lsof -i tcp:8080 COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NA ...
- LA-5052 (暴力)
题意: 给[1,n]的两个排列,统计有多少个二元组(a,b)满足a是A的连续子序列,b是B的连续子序列,a,b中包含的数相同; 思路: 由于是连续的序列,且长度相同,可以枚举一个串的子串,找出这个子串 ...
- 【CQ18阶梯赛第8场】题解
[A:HDU2032 杨辉三角]: 简单的递推,或者是基础的DP: 但是只有杨润东一个人1A,整体准确率只有8/37,具体原因不详. 经验:提交前一定要试一下比较特殊的数据或者最大的数据.其次,为了保 ...
- [SDOI 2008] 洞穴勘测
[题目链接] https://www.lydsy.com/JudgeOnline/problem.php?id=2049 [算法] LCT动态维护森林连通性 时间复杂度 : O(NlogN ^ 2) ...
- [USACO 2016Dec] Team Building
[题目链接] https://www.lydsy.com/JudgeOnline/problem.php?id=4742 [算法] 动态规划 用Fi,j,k表示约翰的前i头牛和保罗的前j头牛匹配 , ...
- centos7无故重启-内核升级
最近有一台物理服务器,centos7操作系统,无故重启,每天都会发生这种情况: 解决: 升级内核 CentOS 允许使用 ELRepo,这是一个第三方仓库,可以将内核升级到最新版本,使用ELRepo升 ...
- 任务36:应用Jwtbearer Authentication
任务36:应用Jwtbearer Authentication D:\MyDemos\jesse 新建项目:dotnet new webapi --name JwtAuthSample VS2017运 ...
- 任务39:Role以及Claims授权
基于Role角色的授权 asp.net core在逐渐淘汰这种基于RoleBase的基于角色的授权.鼓励大家使用基于Claim的授权 在认证的时候Cliam已经加入了Role 注释38节课的 自定义验 ...