How to display both icon and title of action inside ActionBar?

前端 未结 10 2029
庸人自扰
庸人自扰 2020-11-29 18:08

I need to display both icon and title of action inside ActionBar.

I\'ve tried \"withText\" option, but it has no

10条回答
  •  既然无缘
    2020-11-29 18:50

    The solution I find is to use custom action Layout: Here is XML for menu.

    
    
        
    
    

    The Layout is

    
    
    
    
    
    
    
    

    this will show the icon and the text together.

    To get the clickitem the the fragment or activity:

    public void onCreateOptionsMenu(Menu menu, MenuInflater inflater)
    {
        //super.onCreateOptionsMenu(menu, inflater);
        inflater.inflate(R.menu.menu_details_fragment, menu);
        View view = menu.findItem(R.id.action_create).getActionView();
        view.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(getActivity(), "Clicked", Toast.LENGTH_SHORT).show();
            }
        });
    }
    

提交回复
热议问题