当我点击搜索图标工具栏时,我在我的工具栏菜单中使用搜索正在搜索视图中出现。我只想搜索视图。我的搜索点击:
else if (id == R.id.search) {
if (Connectivity.isConnected(MainActivity.this)) {
// removePIP();
// Intent intent = new Intent(MainActivity.this,
SearchActivity.class);
// intent.putExtra("type", "search");
// startActivityForResult(intent, activityRequestCode);
Bundle bundle = new Bundle();
bundle.putString("type", "search");
SearchFragment searchFragment =new SearchFragment();
searchFragment.setArguments(bundle);
FragmentManager fm = getSupportFragmentManager();
fm.beginTransaction()
.add(R.id.container, searchFragment, SearchFragment.class.getSimpleName()).addToBackStack("SearchFragment").commit();
// .add(R.id.youtube_player, youtubeFragment)
overridePendingTransition(R.anim.enter_from_right,
R.anim.exit_to_left);
} else {
Utils.showNoConnectionToast(MainActivity.this);
}
// } else if (id == R.id.voice_search) {
// if (Connectivity.isConnected(MainActivity.this)) {
// Intent intent = new Intent(MainActivity.this,
SearchActivity.class);
// intent.putExtra("type", "voicesearch");
// startActivityForResult(intent, activityRequestCode);
// overridePendingTransition(R.anim.enter_from_right,
R.anim.exit_to_left);
// } else {
// Utils.showNoConnectionToast(MainActivity.this);
// }
}
return super.onOptionsItemSelected(item);
}
答案 0 :(得分:0)
您可以使用此
从SearchFragment
课程中删除工具栏
public class SearchFragment extends Fragment {
private Toolbar toolbar; // declare toolbar in fragment
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container
, @Nullable Bundle savedInstanceState) {
super.onCreateView(inflater, container, savedInstanceState);
View view = inflater.inflate(R.layout.fragment_search, container);
toolbar = getActivity().findViewById(R.id.toolbar); // initialise toolbar
toolbar.setVisibility(View.GONE); // set visibility gone
return view;
}
@Override
public void onStop() {
toolbar.setVisibility(View.VISIBLE); // make it visible when your fragment stops
super.onStop();
}
}