Java 如何在android上显示消息?

Java 如何在android上显示消息?,java,android,label,Java,Android,Label,如何在Android上不使用Toast就可以显示几秒钟的消息? 这个箱子可以用标签吗 创建一个弹出屏幕,并在创建弹出窗口时启动计数器。当计数器结束时,杀死弹出窗口。 如果您想显示一段时间的消息,可以使用AlertDialog.Builder,然后使用Toast是一种更好的方法。您可以根据需要自定义Toast消息,使其看起来像真正的弹出消息 Java代码 toast_自定义_布局 对处理程序的postDelayed()使用自定义对话框 Button btn = (Button) findViewB

如何在Android上不使用Toast就可以显示几秒钟的消息?
这个箱子可以用标签吗

创建一个弹出屏幕,并在创建弹出窗口时启动计数器。当计数器结束时,杀死弹出窗口。
如果您想显示一段时间的消息,可以使用AlertDialog.Builder,然后使用Toast是一种更好的方法。您可以根据需要自定义Toast消息,使其看起来像真正的弹出消息

Java代码 toast_自定义_布局
对处理程序的postDelayed()使用自定义对话框
Button btn = (Button) findViewById(R.id.button1);
        btn.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                LayoutInflater inflater = getLayoutInflater();
                View layout = inflater.inflate(R.layout.toast_custom_layout,
                        (ViewGroup) findViewById(R.id.toast_layout_root));

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

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

    <ImageView
        android1:id="@+id/imageView1"
        android1:layout_width="wrap_content"
        android1:layout_height="match_parent"
        android1:src="@drawable/red_heart" />

    <TextView
        android1:id="@+id/textView1"
        android1:layout_width="wrap_content"
        android1:layout_height="match_parent"
        android1:text="This is custom Toast message"
        android1:textAppearance="?android:attr/textAppearanceMedium" />

</LinearLayout>