`

图片文字可视化提醒Toast与LinearLayout View

 
阅读更多

 

图片文字可视化提醒Toast是将定义的Layout包含(TextView  ImageView)等放在Toast中让提示的Toast对象不只是图片也可以图片文字并存

 

首先定一个Activity;

package cn.com.hwttnet;

import android.app.Activity;
import android.os.Bundle;
import android.text.util.Linkify;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

public class EX05_07Activity extends Activity {

	private Button show;

	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);
		show = (Button) findViewById(R.id.btn);
		show.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				ImageView iv = new ImageView(getApplication());
				TextView tv = new TextView(getApplication());
				LinearLayout lly = new LinearLayout(getApplication());
				//tv.setText("http:www.baidu.com");
				//tv.setText("显示汉字你好");
				tv.setText("15930738139");
				//判断tv的内容为何,并与系统做链接
				Linkify.addLinks(tv, Linkify.WEB_URLS | Linkify.EMAIL_ADDRESSES
						| Linkify.PHONE_NUMBERS);
				//用Toast显示方式
				Toast toast = Toast.makeText(EX05_07Activity.this ,
						tv.getText(), Toast.LENGTH_LONG);
				//自定义View
				View textView=toast.getView();
				//以水平方式排列
				lly.setOrientation(LinearLayout.HORIZONTAL);
				//在ImageView里面指定要显示的图片
				iv.setImageResource(R.drawable.ic_launcher);
				//在Layout里面添加创建的View 图片
				lly.addView(iv);
				//在Toast里面显示文字  就是显示的那些汉字
				lly.addView(textView);
				//以toast setView方法将LinearLayout传入
				toast.setView(lly);

				toast.show();

			}
		});
	}
}

 

main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >
 <Button 
     android:id="@+id/btn"
     android:layout_width="fill_parent"
     android:layout_height="wrap_content"
     android:text="显示具有图片跟文字的Toast"
     />

</LinearLayout>

 <!--StartFragment -->

 
分享到:
评论

相关推荐

    android 图文可视化提醒 Toast与LinearLayout View

    android 图文可视化提醒 Toast与LinearLayout View

    Google Android SDK开发范例大全(PDF高清完整版3)(4-3)

    5.7 图文可视化提醒——Toast与LinearLayoutView 5.8 状态栏的图标与文字提醒——NotificationManager与Notification对象的应用 5.9 搜索手机通讯录自动完成——使用ContentResolver 5.10 取得联系人资料——...

    Google Android SDK开发范例大全(PDF完整版4)(4-4)

    5.7 图文可视化提醒——Toast与LinearLayoutView 5.8 状态栏的图标与文字提醒——NotificationManager与Notification对象的应用 5.9 搜索手机通讯录自动完成——使用ContentResolver 5.10 取得联系人资料——...

    Google Android SDK开发范例大全(PDF高清完整版1)(4-1)

    5.7 图文可视化提醒——Toast与LinearLayoutView 5.8 状态栏的图标与文字提醒——NotificationManager与Notification对象的应用 5.9 搜索手机通讯录自动完成——使用ContentResolver 5.10 取得联系人资料——...

    Google Android SDK开发范例大全的目录

    5.7 图文可视化提醒——Toast与LinearLayoutView 5.8 状态栏的图标与文字提醒——NotificationManager与Notification对象的应用-p178 5.9 搜索手机通讯录自动完成——使用ContentResolver-p82 5.10 取得联系人资料...

    Google+Android+SDK开发范例大全

    5.7 图文可视化提醒——Toast与LinearLayoutView 5.8 状态栏的图标与文字提醒——NotificationManager与Notification对象的应用 5.9 搜索手机通讯录自动完成——使用ContentResolver 5.10 取得联系人资料——...

    Google Android SDK开发范例大全(完整版附部分源码).pdf

    5.7 图文可视化提醒——Toast与LinearLayoutView 5.8 状态栏的图标与文字提醒——NotificationManager与Notification对象的应用 5.9 搜索手机通讯录自动完成——使用ContentResolver 5.10 取得联系人资料——...

    Google Android sdk 开发范例大全 部分章节代码

    5.7 图文可视化提醒——Toast与LinearLayoutView 5.8 状态栏的图标与文字提醒——NotificationManager与Notification对象的应用-p178 5.9 搜索手机通讯录自动完成——使用ContentResolver-p82 5.10 取得联系人资料...

    Google Android SDK 开发范例大全01

    5.7 图文可视化提醒——Toast与LinearLayoutView 5.8 状态栏的图标与文字提醒——NotificationManager与Notification对象的应用-p178 5.9 搜索手机通讯录自动完成——使用ContentResolver-p82 5.10 取得联系人资料...

    Google Android SDK 开发范例大全02

    5.7 图文可视化提醒——Toast与LinearLayoutView 5.8 状态栏的图标与文字提醒——NotificationManager与Notification对象的应用-p178 5.9 搜索手机通讯录自动完成——使用ContentResolver-p82 5.10 取得联系人资料...

    Google Android SDK开发范例大全(完整版)

    5.7 图文可视化提醒——Toast与LinearLayoutView 5.8 状态栏的图标与文字提醒——NotificationManager与Notification对象的应用 5.9 搜索手机通讯录自动完成——使用ContentResolver 5.10 取得联系人资料——...

Global site tag (gtag.js) - Google Analytics