发布于 2016-05-19 11:55:54 | 133 次阅读 | 评论: 0 | 来源: 网友投递

这里有新鲜出炉的精品教程,程序狗速度看过来!

Android移动端操作系统

Android是一种基于Linux的自由及开放源代码的操作系统,主要使用于移动设备,如智能手机和平板电脑,由Google公司和开放手机联盟领导及开发。尚未有统一中文名称,中国大陆地区较多人使用“安卓”或“安致”。


这篇文章主要介绍了Android实现Toast提示框图文并存的方法,实例分析了Toast提示框的参数设置及图文调用的相关技巧,需要的朋友可以参考下

本文实例讲述了Android实现Toast提示框图文并存的方法。分享给大家供大家参考,具体如下:

程序如下:


import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.text.util.Linkify;
import android.view.Gravity;
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 A05Activity extends Activity {
 private Button b;
  /** Called when the activity is first created. */
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    b=(Button)findViewById(R.id.button);
    b.setText("显示Toast");
    b.setBackgroundColor(Color.GREEN);
    b.setOnClickListener(new OnClickListener(){
  @Override
  public void onClick(View v) {
  // TODO Auto-generated method stub
  ImageView iv=new ImageView(A05Activity.this);
     iv.setImageResource(R.drawable.icon);
     TextView tv=new TextView(A05Activity.this);
     tv.setText(R.string.title);
     LinearLayout ll=new LinearLayout(A05Activity.this);
     //判断TextView中的内容是什么格式,并与系统连接
     Linkify.addLinks(tv, Linkify.PHONE_NUMBERS|Linkify.EMAIL_ADDRESSES|Linkify.WEB_URLS);
  Toast t=Toast.makeText(A05Activity.this, tv.getText(), Toast.LENGTH_LONG);
  View v1=t.getView();
  ll.setOrientation(LinearLayout.VERTICAL);
  ll.addView(iv);
  ll.addView(v1);
  t.setView(ll);
  //设置Toast对象在手机中的相对位置
  t.setGravity(Gravity.CENTER, 50, 50);
  t.show();
  }
    });
  }
}

注意:因为Toast属于Activiyt里的Context,所以在Toast里面的连接是无法单击的。比如在Toast中存在网址等内容是无法在Toast里面双击打开的。



最新网友评论  共有(0)条评论 发布评论 返回顶部

Copyright © 2007-2017 PHPERZ.COM All Rights Reserved   冀ICP备14009818号  版权声明  广告服务