2015-05-14 60 views
0

我想自定義操作欄添加到一個片段按鈕ID沒有在自定義操作欄獲得

public View onCreateView(LayoutInflater inflater, ViewGroup container, 
      Bundle savedInstanceState) { 
     // TODO Auto-generated method stub 
     View view = inflater.inflate(R.layout.fragment_createblog, container,false);     

     android.app.ActionBar actionBar = getActivity().getActionBar();  
     actionBar.setCustomView(R.layout.actionbar_createblog);  
     actionBar.setDisplayShowCustomEnabled(true); 
     actionBarBlogCreation = (Button) view.findViewById(R.id.button_actionbarBlog); 
     actionBarBlogCreation.setOnClickListener(this); 

     } 
}); 

我動作條被改變,但是當我試圖從佈局走按鈕ID它顯示爲空。爲什麼會發生?

回答

1

我想你接下來應該嘗試:

actionBar.setCustomView(R.layout.actionbar_createblog);  
      actionBar.setDisplayShowCustomEnabled(true); 
      actionBarBlogCreation = (Button) actionBar.getCustomView().findViewById(R.id.button_actionbarBlog);