我需要創建自定義動畫Toast消息。現在我需要知道這是否可能。我創建了一個自定義視圖的烤麪包,但我無法弄清楚如何將自定義動畫添加到烤麪包。Android將自定義動畫添加到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();
}
});
}
是不是很容易創建一個自定義視圖,看起來像烤麪包,並適用於任何你想要的? –
看這裏:[Toast進入/退出的自定義動畫](http://stackoverflow.com/questions/14012602/custom-animation-for-toast-enter-exit)你不能將自定義動畫添加到Toast只有自定義View你已經完成了。 – Sajmon
根據@Sajmon的回答和這個http://developer.android.com/guide/topics/graphics/view-animation.html簡單地將動畫添加到視圖中,就像您對任何其他視圖所做的一樣,我不確定是否它會工作,但嘗試一下! – Andres