使用片段构建基本 android 应用

building a basic android app with fragments

我想写一个 android 应用程序启动主要 activity 只显示动画,然后在 1 秒后文本 hello 打印在他旁边并且只在那里停留 2 秒。之后出现新文本并停留 4 秒。我该怎么做?

你想用 toast 还是什么来显示消息?

如果答案是吐司,可以试试这个方法!

"msg" 参数是您的消息,"tempo" 参数是您希望消息显示多长时间(在 MS 中)。我希望它能帮助你,朋友! :)

public static void Msg(Activity activity, String msg, int tempo)
{
    final Toast toast = Toast.makeText(activity, msg, Toast.LENGTH_SHORT);
    toast.show();

    //for how long the message will be shown
    Handler handler = new Handler();
    handler.postDelayed(new Runnable() {
        @Override
        public void run() {
            toast.cancel();
        }
    }, tempo);
}