2011.07.11——— android 自定义toast


自定义toast方法
protected void showToast() {        // create the view        View view = inflateView(R.layout.incoming_message_panel);        // set the text in the view        TextView tv = (TextView)view.findViewById(R.id.message);        tv.setText("khtx. meet u for dinner. cul8r");        // show the toast        Toast toast = new Toast(this);        toast.setView(view);        toast.setDuration(Toast.LENGTH_LONG);        toast.show();    }    private View inflateView(int resource) {        LayoutInflater vi = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);        return vi.inflate(resource, null);    }


xml:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:layout_width="match_parent"    android:layout_height="wrap_content"    android:background="@android:drawable/toast_frame">    <LinearLayout        android:orientation="horizontal"        android:layout_width="match_parent"        android:layout_height="wrap_content">            <ImageView                android:layout_width="wrap_content"                android:layout_height="wrap_content"                android:src="@drawable/sample_thumb_2"                />            <TextView                android:id="@+id/message"                android:layout_gravity="center_vertical"                android:layout_width="wrap_content"                android:layout_height="wrap_content"                android:paddingLeft="6dip"                />    </LinearLayout></FrameLayout>






更多相关文章

  1. 三步搞定:Vue.js调用Android原生方法
  2. android 防止键盘弹出的简单方法
  3. Android高手进阶教程(十七)之---Android中Intent传递对象的两种
  4. Android的消息机制,用Android线程间通信的Message机制,Android中Ha
  5. Android获取本机电话号码的简单方法
  6. 如何在eclipse的android工程里引用android sdk之外的类和方法
  7. android studio在模拟器上的中文乱码问题解决方法

随机推荐

  1. 第6章 数据存储
  2. Android Network数据存储
  3. Android TextView 给文本中指定片段添加
  4. WeakReference 在android中的应用
  5. Android中JSON数据格式的简单使用
  6. Android实现两次按下返回键退出
  7. Unity捕获Android的系统返回键
  8. android studio jni路径配置
  9. Android.jar文件分析
  10. Android(安卓)2016年度知名企业公司面试