小编Jaw*_*man的帖子

如何在动作栏上使用按钮使用碎片?

我想在片段的操作栏上添加按钮.但是我在下面给出的代码上收到错误.

这是我的片段代码,我想在此选项卡的操作栏上添加按钮

@Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
         final View view = inflater.inflate(R.layout.credit_main, container, false);
return view;
    }
@Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu items for use in the action bar
        MenuInflater inflater = getMenuInflater();

        inflater.inflate(R.menu.search_menu, menu);
        return super.onCreateOptionsMenu(menu);
    }


    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            // action with ID action_refresh was selected
            case R.id.search:
                Toast.makeText(getActivity(), "Refresh selected", Toast.LENGTH_SHORT)
                        .show();
                break;
            default:
                break;
        }
        return super.onOptionsItemSelected(item);
    }

}
Run Code Online (Sandbox Code Playgroud)

这里的错误是 …

android button android-fragments android-actionbar

0
推荐指数
2
解决办法
1636
查看次数