【发布时间】:2023-03-27 08:02:01
【问题描述】:
我在一个需要自定义工具栏的类中扩展了 Fragment Activity。因此,我添加了获取工具栏的代码,但 setSupportActionBar(toolbar) 不起作用。然后,我添加了 AppCompatActivity.getActivity() 进行转换,但效果不佳。
这里是代码 -
public class main_fragment extends FragmentActivity implements FragmentDrawer.FragmentDrawerListener {
private Toolbar toolbar;
private FragmentDrawer drawerFragment;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_fragment);
toolbar = (Toolbar) findViewById(R.id.tool_bar);
((AppCompatActivity) getActivity()).setSupportActionBar(toolbar);
((AppCompatActivity) getActivity()).getSupportActionBar().setDisplayShowHomeEnabled(true);
drawerFragment = (FragmentDrawer)
getSupportFragmentManager().findFragmentById(R.id.fragment_navigation_drawer);
drawerFragment.setUp(R.id.fragment_navigation_drawer, (DrawerLayout) findViewById(R.id.drawer_layout), toolbar);
drawerFragment.setDrawerListener(this);
}
【问题讨论】:
-
我试过了。没用。它显示无法解析“ActionBarCompat”的符号。
标签: android fragment android-fragmentactivity android-toolbar