1
我想要實現簡單的任務 - 在對話框關閉之前,我想根據我的邏輯設置不同的關閉動畫(getWindow()。getAttributes()。windowAnimations = ...)。例如,我在對話框上有2個按鈕,如果按下第一個按鈕,我想向左滑動,如果按下第二個按鈕,向右滑動。我創建了一些帶有android:windowExitAnimation和android:windowEnterAnimation動畫的樣式文件,如果在自定義對話框構造函數中傳遞,它們將工作。但我不能覆蓋代碼中的windowAnimations作爲構造函數的方法不能使用,因爲我需要不同的動畫。如何做到這一點,以及爲什麼這段代碼無法正常工作?在運行時更改動畫
// close button
_button_close = (ImageButton)findViewById(R.id.buttonClose);
if (_button_close != null)
{
_button_close.setOnClickListener(
new Button.OnClickListener()
{
public void onClick(View v)
{
// set animation
getWindow().getAttributes().windowAnimations = R.style.DialogSlideOutLeft;
// close form
dismiss();
}
}
);
}
沒有任何影響爲了我 – stoefln