2015-04-27 24 views
0

獲取發現秀(動作條,String)方法DialogFragment.show(FragmentTransaction,串)沒有合適的方法是不適用

Error:(192, 23) error: no suitable method found for show(ActionBar,String) 
method DialogFragment.show(FragmentTransaction,String) is not applicable 
(actual argument ActionBar cannot be converted to FragmentTransaction by method invocation conversion) 
method DialogFragment.show(FragmentManager,String) is not applicable 
(actual argument ActionBar cannot be converted to FragmentManager by method invocation conversion) 

試圖創建一個自定義對話框時,得到錯誤dialog.show(getSupportActionBar(), "dialog");此代碼。

這裏是我的簡單代碼:

public boolean onPrepareOptionsMenu(android.view.Menu menu) { 
    // if nav drawer is opened, hide the action items 
    boolean drawerOpen = mDrawerLayout.isDrawerOpen(mDrawerList); 
    menu.findItem(R.id.action_settings).setVisible(!drawerOpen); 
    Button settBtn = (Button) findViewById(R.id.action_settings); 
    settBtn.setOnClickListener(new View.OnClickListener() { 
     @SuppressWarnings("deprecation") 
     public void onClick(View v) { 
      CustomDialogFragment dialog = new CustomDialogFragment(); 
      dialog.show(getSupportActionBar(), "dialog"); 

     } 
    }); 
    return super.onPrepareOptionsMenu(menu); 
} 

public class CustomDialogFragment extends DialogFragment { 
    @Override 
    public Dialog onCreateDialog(Bundle savedInstanceState) { 
     Dialog dialog = new Dialog(getActivity()); 
     dialog.getWindow().getAttributes().windowAnimations = R.style.Animation_CustomDialog; 
     dialog.getWindow().requestFeature(Window.FEATURE_NO_TITLE); 
     dialog.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN); 
     dialog.setContentView(R.layout.dialog_custom); 
     dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT)); 
     dialog.setCanceledOnTouchOutside(false); 
     TextView message = (TextView) dialog.findViewById(R.id.message); 
     message.setText(">>>>>>>"); 
     dialog.findViewById(R.id.positive_button).setOnClickListener(new View.OnClickListener() { 
      public void onClick(View v) { 
       dismiss(); 
      } 
     }); 

     dialog.findViewById(R.id.close_button).setOnClickListener(new View.OnClickListener() { 
      public void onClick(View v) { 
       dismiss(); 
      } 
     }); 
     return dialog; 
    } 
} 

請幫我解決提前this.Thanks .....

+1

對話解決.show()接受FragmentTransaction或FragmentManager作爲第一個參數,爲什麼傳遞一個ActionBar? – Egor

+0

其實它的一個擴展類的ActionBarActivity –

回答

0
DialogFragment fragment = new DialogFragment(); 
fragment.show(getSupportFragmentManager(), "dialog"); 
+2

介意[解釋你的解決方案](http://stackoverflow.com/help/how-to-answer)有點?你可能想閱讀[我如何寫出一個好答案](http://stackoverflow.com/help/how-to-answer)。 –

1

使用FragmentManager

FragmentManager fm; 
fm= getFragmentManager(); 
CustomDialogFragment dialog = new CustomDialogFragment(); 
dialog.show(fm , "dialog"); 
相關問題