标签:风飞雪未扬 从零开始学android toast土司提示组件
|
No.
|
方法及常量
|
类型
|
描述
|
|
1
|
public static final int LENGTH_LONG
|
常量
|
显示时间长
|
|
2
|
public static final int LENGTH_SHORT
|
常量
|
显示时间短
|
|
3
|
public Toast(Context context)
|
普通
|
创建Toast对象
|
|
4
|
public static Toast makeText(Context context, int resId, int duration)
|
普通
|
创建一个Toast对象,并指定显示文本资源的ID,和信息的显示时间
|
|
5
|
public static Toast makeText(Context context, CharSequence text, int duration)
|
普通
|
创建一个Toast对象,并指定显示文本资源,和信息的显示时间
|
|
6
|
public void show()
|
普通
|
显示信息
|
|
7
|
public void setDuration(int duration)
|
普通
|
设置显示的时间
|
|
8
|
public void setView(View view)
|
普通
|
设置显示的View组件
|
|
9
|
public void setText(int resId)
|
普通
|
设置显示的文字资源ID
|
|
10
|
public void setText(CharSequence s)
|
普通
|
直接设置要显示的文字
|
|
11
|
public void setGravity(int gravity, int xOffset, int yOffset)
|
普通
|
设置组件的对齐方式
|
|
12
|
public View getView()
|
普通
|
取得内部包含的View组件
|
|
13
|
public int getXOffset()
|
普通
|
返回组件的X坐标位置
|
|
14
|
public int getYOffset()
|
普通
|
返回组件的Y坐标位置
|
|
15
|
public void cancel()
|
普通
|
取消显示
|
<span style="font-size:14px;"><?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:background="#DAAA"
android:orientation="horizontal"
android:padding="10dp" >
<ImageView
android:id="@+id/image"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_marginRight="10dp"
android:src="@drawable/kill"
/>
<TextView
android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:text="自定义的提示"
/>
</LinearLayout></span><span style="font-size:14px;">package com.example.toast;
import android.app.Activity;
import android.os.Bundle;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
public class MainActivity extends Activity {
private Button button1, button2;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
button1 = (Button) this.findViewById(R.id.button1);
button2 = (Button) this.findViewById(R.id.button2);
button1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
// 原始的提示
Toast.makeText(MainActivity.this, "自定义的提示框", Toast.LENGTH_SHORT)
.show();
}
});
// 为button设置单击事件
button2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
View view = LayoutInflater.from(MainActivity.this).inflate(
R.layout.linearlayout, null);// 将Layout布局转换为View对象
Toast toast = new Toast(MainActivity.this);// 创建Toast提示
toast.setGravity(Gravity.CENTER, 0, 0);// 设置Toast提示的位置
toast.setView(view);// 将布局增加到Toast组件当中
toast.show();// 显示提示
}
});
}
}
</span>从零开始学android<Toast土司提示组件.二十.>,布布扣,bubuko.com
标签:风飞雪未扬 从零开始学android toast土司提示组件
原文地址:http://blog.csdn.net/u013616976/article/details/38581159