Toast用法
来源:互联网 发布:数据库冗余 anomalies 编辑:程序博客网 时间:2024/05/16 05:37
设置Toast显示字体大小颜色
- LayoutInflater inflater = LayoutInflater
- .from(getApplicationContext());
- View view = inflater.inflate(R.layout.my_toast,
- (ViewGroup) findViewById(R.id.toast_layout_root));
- TextView textView = (TextView) view.findViewById(R.id.text);
- SpannableString ss = new SpannableString("扫描成功");
- ss.setSpan(new ForegroundColorSpan(Color.RED), 0, 4,
- Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
- textView.setText(ss);
- toast.setDuration(Toast.LENGTH_LONG);
- toast.setView(view);
- toast.setGravity(Gravity.CENTER, 0, 0);
- toast.show();
- mytoast.xml
- <?xml version="1.0" encoding="utf-8"?>
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:id="@+id/toast_layout_root"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- android:orientation="horizontal"
- android:padding="10dp" >
- <TextView
- android:layout_marginTop="800dip"
- android:textSize="25dip"
- android:id="@+id/text"
- android:layout_width="wrap_content"
- android:layout_height="fill_parent"
- android:layout_marginLeft="50dip"
- android:textColor="@color/black" />
- </LinearLayout>
设置Toast显示位置
两个方法可以设置显示位置:
方法一:setGravity(int gravity, int xOffset, int yOffset)三个参数分别表示(起点位置,水平向右位移,垂直向下位移)
方法二:setMargin(float horizontalMargin, float verticalMargin)
以横向和纵向的百分比设置显示位置,参数均为float类型(水平位移正右负左,竖直位移正上负下)
Toast toast = Toast.makeText(this,"最高记录:" + pre.getLong("total", 0), Toast.LENGTH_LONG);
toast.setGravity(Gravity.TOP , 0, 50);
toast.show();
0 0
- Toast用法
- Toast用法
- Toast用法
- Toast用法
- Toast用法
- Toast用法
- Toast用法
- toast用法
- Toast用法!!
- android-Toast的用法
- Android Toast用法
- Toast 的用法
- 【android】Toast用法总结
- Android Toast 的用法
- Android Toast 用法总结
- Toast.makeText用法
- Toast的简单用法
- Toast的基本用法
- android 获取控件在屏幕中位置
- jQuery 操作DOM总结,DOM Core操作,HTML-DOM操作和CSS-DOM操作
- 谷歌电子市场学习笔记第一天之下
- oracle 删除用户
- Kinect for Windows SDK开发入门(五):景深数据处理 下
- Toast用法
- HDU 1165 Eddy's research II 打表找规律
- VS 按F5无法自动编译
- 深入分析JavaWeb Item19 -- 基于Servlet+JSP+JavaBean开发模式的用户登录注册
- squid介绍及其简单配置
- 关于 DOM 操作的几个类型
- GLSurfaceView简介
- 【学习】nodeJS工具模块——util
- hdu 5596 GTW likes gt