片段中工具栏中的setTitle提供了空指针异常

时间:2019-03-23 07:04:59

标签: android-fragments

我正在尝试在工具栏上的片段中设置标题,但显示空指针异常

@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    toolbar = (Toolbar) getView().findViewById(R.id.schedule_toolbar);
    toolbar.setTitle("");
    ((AppCompatActivity)(getActivity())).setSupportActionBar(toolbar);
    toolbar.setTitle("Schedule");

    //((AppCompatActivity)(getActivity())).getSupportActionBar().setHomeButtonEnabled(true);
    //((AppCompatActivity)(getActivity())).getSupportActionBar().setDisplayHomeAsUpEnabled(true);

}

0 个答案:

没有答案