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之Loader理解
  3. android 防止键盘弹出的简单方法
  4. Android(安卓)UI开发第十七篇――Android(安卓)Fragment实例
  5. android 获取包名的两种方式
  6. Android(安卓)文件下载 downloadManager
  7. Android——AppWidgetProvider应用
  8. android:configChanges
  9. Android进程 Handler Message Looper

随机推荐

  1. 库管理员必备-WMS仓库管理软件
  2. Python运维自动化开发之Fabric模块
  3. 玩了这么久Linux,这些使用技巧你可能还不
  4. Java 并发编程 join 方法的使用
  5. Tomcat性能调优及JVM内存工作原理
  6. 30个必知的Linux命令技巧,你都掌握了吗?
  7. 高级运维工程师的打怪升级之路
  8. 租用服务器时,为什么还要购买CDN加速?
  9. 华云大咖说 | 华云数据与瀚高软件携手共
  10. Python发送邮件各种姿势