我正在尝试为DialogFragment设置进入和退出转换,这似乎很简单。下面是创建对话框的DrinkDetailActivity代码:
fab.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v) {
//create and display the dialog
DialogFragment orderFragment = new OrderDrinkDialogFragment();
//set the slide transition for the fragment
Transition dialSlide = new Slide();
dialSlide.setDuration(300);
orderFragment.setEnterTransition(dialSlide);
orderFragment.setExitTransition(dialSlide);
orderFragment.show(getFragmentManager(), "order");
}
});
以下是我OrderDrinkDialogFragment类的代码:
public class OrderDrinkDialogFragment extends DialogFragment
{
@Override
public Dialog onCreateDialog(Bundle savedInstanceState)
{
AlertDialog.Builder builder = new AlertDialog.Builder(DrinkDetailActivity.activity);
//set up the Linear Layout of the dialog
LinearLayout layout = new LinearLayout(DrinkDetailActivity.activity);
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.WRAP_CONTENT);
layout.setOrientation(LinearLayout.VERTICAL);
layout.setLayoutParams(params);
//set up the EditText view
EditText nameField = new EditText(DrinkDetailActivity.activity);
nameField.setHint(R.string.dialog_name_hint);
//add the EditText view to the layout
layout.addView(nameField, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.WRAP_CONTENT));
//set layout as the view of the dialog
builder.setView(layout);
return builder.create();
}
}
DrinkDetailActivity.activity
指的是在 DrinkDetailActivity
实例内部的 this
。但出现了一个问题,当我使用 show()
或者关闭对话框时,它并没有过渡效果,只是简单地弹入和弹出视图。这篇教程帮助我解决了应用程序中其余部分的 Activity 过渡问题,我也按照相同的说明进行了 Fragment 过渡。请问我做错了什么?
java.lang.NullPointerException: Attempt to invoke virtual method 'android.view.Window android.app.Dialog.getWindow()' on a null object reference
。这很有道理,因为在对话框创建之前,我怎么能获取对话框的窗口呢? - mithunm93Dialog dialog = builder.create();
而不是调用super。非常感谢您的帮助!不确定是否应该在这里问,但是如何让对话框从底部导航栏下面滑出呢? - mithunm93