简体   繁体   中英

button id is not getting in custom action bar

I am trying to add a custom action bar to a fragment

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);

      } 
 });

My action bar is changed, but while i am trying to take the button id from the layout it shows null. Why it is happening ?

I think you should try next:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM