2017-01-26 15 views
2

これでフローq/a以上のスタックをすべてチェックしても解決策が見つかりません。ここでダイアログフラグメントでアニメーションが入力されず、終了しません

は、ファイルは次のとおりです。

DialogFragment.java

package app.com.thetechnocafe.mealsquickie.Dialogs; 

import android.app.Dialog; 
import android.os.Bundle; 
import android.support.annotation.NonNull; 
import android.support.annotation.Nullable; 
import android.support.design.widget.TextInputEditText; 
import android.support.design.widget.TextInputLayout; 
import android.support.v4.app.DialogFragment; 
import android.view.LayoutInflater; 
import android.view.View; 
import android.view.ViewGroup; 
import android.widget.Button; 
import android.widget.Toast; 

import app.com.thetechnocafe.mealsquickie.R; 
import butterknife.BindView; 
import butterknife.ButterKnife; 

/** 
* Created by gurleensethi on 26/01/17. 
*/ 

public class NewCategoryDialog extends DialogFragment { 

    @BindView(R.id.category_name_text_input_layout) 
    TextInputLayout mCategoryNameTextInputLayout; 
    @BindView(R.id.category_name_text_input_edit_text) 
    TextInputEditText mCategoryNameTextInputEditText; 
    @BindView(R.id.cancel_button) 
    Button mCancelButton; 
    @BindView(R.id.add_button) 
    Button mAddButton; 

    private OnAddCategoryListener mListener; 

    //Interface for callbacks 
    public interface OnAddCategoryListener { 
     void onCategoryAdded(String category); 
    } 

    //Instance method 
    public static NewCategoryDialog getInstance() { 
     return new NewCategoryDialog(); 
    } 

    @Nullable 
    @Override 
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { 
     //Inflate the custom dialog 
     View root = LayoutInflater.from(getContext()).inflate(R.layout.dialog_new_category, container, false); 

     ButterKnife.bind(this, root); 

     setEventListeners(); 

     //Set properties 
     getDialog().requestWindowFeature(STYLE_NO_TITLE); 
     setCancelable(false); 

     return root; 
    } 

    @Override 
    public void onStart() { 
     super.onStart(); 
     getDialog().getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); 
    } 

    private void setEventListeners() { 
     mCancelButton.setOnClickListener(view -> getDialog().dismiss()); 

     mAddButton.setOnClickListener(view -> validateAndSubmitFields()); 
    } 

    private void validateAndSubmitFields() { 
     if (mListener != null) { 
      //Remove all the already existing errors 
      mCategoryNameTextInputLayout.setErrorEnabled(false); 

      String category = mCategoryNameTextInputEditText.getText().toString(); 

      if (category.equals("")) { 
       mCategoryNameTextInputLayout.setError(getString(R.string.category_name_cannot_be_empty)); 
       return; 
      } 

      mListener.onCategoryAdded(category); 
     } else { 
      Toast.makeText(getContext(), "No Listener attached for adding new category. Please contact the developer.", Toast.LENGTH_SHORT).show(); 
     } 
    } 

    @NonNull 
    @Override 
    public Dialog onCreateDialog(Bundle savedInstanceState) { 
     Dialog dialog = super.onCreateDialog(savedInstanceState); 

     dialog.getWindow().getAttributes().windowAnimations = R.style.DialogSlideFromBottomAnimation; 
     return dialog; 
    } 
} 

slide_down.xml

<?xml version="1.0" encoding="utf-8"?> 
<set xmlns:android="http://schemas.android.com/apk/res/android"> 
    <translate 
     android:duration="1000" 
     android:fromYDelta="0%" 
     android:interpolator="@android:anim/accelerate_interpolator" 
     android:toYDelta="100%" /> 
</set> 

slide_up.xmlダイアログを表示

<?xml version="1.0" encoding="utf-8"?> 
<set xmlns:android="http://schemas.android.com/apk/res/android"> 
    <translate 
     android:duration="1000" 
     android:fromYDelta="100%" 
     android:interpolator="@android:anim/accelerate_interpolator" 
     android:toYDelta="0%" /> 
</set> 

DialogFragment dialog = NewCategoryDialog.getInstance(); 
dialog.show(getFragmentManager(), DIALOG_NEW_CATEGORY_TAG); 

は私がgetAttributes().windowAnimationssetWindowAnimations()の両方を試してみました、ともonActivityCreated、onCreateDialog、onCreateViewでそれを入れて、それを試してみましたが、動作するようには思えません。

答えて

0

このように試してください。

@Override 
    public void onActivityCreated(Bundle savedInstanceState) { 
     super.onActivityCreated(savedInstanceState); 

     if (getDialog().getWindow() != null) { 
      dialog.getWindow().getAttributes().windowAnimations = R.style.DialogSlideFromBottomAnimation; 
     } 
    } 
関連する問題