1

我有一個4片段(MyNavigationBarMaster,MyNavigationBarDetails,Master e Details)的平板電腦應用程序。當隱藏鍵盤時,片段事務的自定義動畫消失

I'use的片段交易,並自定義動畫(IPHON式)如下:

FragmentTransaction mfragmentTransaction = getFragmentManager().beginTransaction(); 
mfragmentTransaction.setCustomAnimations(R.anim.slide_in_left, R.anim.slide_out_left, R.anim.slide_out_right, R.anim.slide_in_right); 
mfragmentTransaction.replace(R.id.MenuMFragment, new PeopleMFragment()); 
mfragmentTransaction.addToBackStack(null).commit(); 

這個沒有問題,但是當我試圖用這個代碼PeopleMFragment()編程隱藏鍵盤:

@Override 
public void onActivityCreated(Bundle savedInstanceState) { 
    final InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE); 
    imm.hideSoftInputFromWindow(getView().getWindowToken(), 0); 
} 

片段事務的動畫無法正常工作,但鍵盤已隱藏且片段已正確連接。

爲什麼?問題是有一個單一的線程鍵盤和XML動畫? 別人有同樣的問題?在此先感謝

回答

1

試試看。 (我試過htc的願望)

public void nextFragment(){ 

    //close keyboard 
    InputMethodManager inputMethodManager = (InputMethodManager) getActivity().getSystemService(Activity.INPUT_METHOD_SERVICE); 
    inputMethodManager.hideSoftInputFromWindow(getActivity().getCurrentFocus().getWindowToken(), 0); 

    //remove focus, to remove any "auto-suggestions" views from the text field 
    getActivity().getCurrentFocus().clearFocus(); 

    //change fragment 
    Fragment2 newFragment = new Fragment2(); 
    FragmentTransaction transaction = getFragmentManager().beginTransaction(); 
    transaction.setCustomAnimations(R.animator.slide_in_left, R.animator.slide_out_right); 
    transaction.replace(R.id.fragmentContainer, newFragment); 
    transaction.addToBackStack(null); 
    transaction.commit(); 

}//nextFragment 
相關問題