自烤面包的Andr​​oid版本:一个简单的例子例子、版本、简单、烤面包

2023-09-11 20:30:10 作者:潇洒丶疯一回

我是新到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

Custom吐司与模拟时钟