【发布时间】:2013-08-03 15:27:48
【问题描述】:
我需要创建一个自定义动画 toast 消息。现在我需要知道这是否可能。我创建了一个带有自定义视图的 toast,但我不知道如何将自定义动画添加到 toast。
这是我目前的代码。
private void showToast() {
LayoutInflater inflater = getLayoutInflater();
View layout = inflater.inflate(R.layout.custom_toast,
(ViewGroup) findViewById(R.id.custom_toast_layout_id));
// set a message
TextView text = (TextView) layout.findViewById(R.id.toast_text);
text.setText("Button is clicked!");
// Toast...
Toast toast = new Toast(getApplicationContext());
toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
toast.setDuration(Toast.LENGTH_LONG);
toast.setView(layout);
toast.show();
}
});
}
【问题讨论】:
-
创建一个看起来像烤面包的自定义视图并应用到任何你想要的东西是不是很容易?
-
看这里:Custom animation for Toast enter/exit? 您不能将自定义动画添加到您已经完成的仅 Toast 自定义视图中。
-
根据@Sajmon 的回答和这个developer.android.com/guide/topics/graphics/view-animation.html 只需将动画添加到视图中,就像您对任何其他视图所做的那样,我不确定它是否会起作用,但试一试!跨度>
标签: android android-animation toast android-custom-view