自烤面包的Andr​​oid版本:一个简单的例子 [英] Custom toast in android : a simple example

查看:164
本文介绍了自烤面包的Andr​​oid版本:一个简单的例子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新到Android programming.Can任何人给我一个简单的例子显示了Android的定制Toast通知?

I'm new to android programming.Can any one give me a simple example showing a custom toast notification in android?

推荐答案

使用低于$ C $定制敬酒C,这可能是帮助你。

Use below code of custom toast, it may be help you.

toast.xml

toast.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/toast_layout_root"
    android:orientation="horizontal"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:padding="10dp"
    android:background="#DAAA" >

    <ImageView android:id="@+id/image"
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:layout_marginRight="10dp" />

    <TextView android:id="@+id/text"
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:textColor="#FFF" />

</LinearLayout>

MainActivity.java

MainActivity.java

LayoutInflater inflater = getLayoutInflater();
View layout = inflater.inflate(R.layout.toast_layout,
                               (ViewGroup) findViewById(R.id.toast_layout_root));

ImageView image = (ImageView) layout.findViewById(R.id.image);
image.setImageResource(R.drawable.android);
TextView text = (TextView) layout.findViewById(R.id.text);
text.setText("Hello! This is a custom toast!");

Toast toast = new Toast(getApplicationContext());
toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
toast.setDuration(Toast.LENGTH_LONG);
toast.setView(layout);
toast.show();

和检查下面的链接,也可用于定制面包

And Check below links also for custom toast

<一个href="http://androiddesk.word$p$pss.com/2012/01/28/custom-notification-in-android-with-an-example/">Custom吐司与模拟时钟

这篇关于自烤面包的Andr​​oid版本:一个简单的例子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆