Setting a subtitle on my Toolbar from a fragment

前端 未结 4 1002
陌清茗
陌清茗 2020-12-31 13:31

I am having some trouble setting the sub-title in my Toolbar from my fragment. I keep getting a Null Pointer Exception at the setSubTitle.

@Override
public          


        
4条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-31 14:15

    Declare a variable ActionBar toolbar and use it this way:

    toolbar=((AppCompatActivity) getActivity()).getSupportActionBar();
    
    toolbar.setHomeAsUpIndicator(R.drawable.ic_arrow_left);
    toolbar.setTitle("Detalhes");
    

提交回复
热议问题