我从堆栈中看到许多回答使用po,但它们对我没用。
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View rootView = inflater.inflate(R.layout.fragment_new_appointment, container, false);
Toolbar toolbar = (Toolbar)rootView.findViewById(R.id.toolbar_new_appointment);
((DoctorCardActivity)getActivity()).setSupportActionBar(toolbar);
toolbar.setNavigationIcon(R.drawable.ic_arrow_back_white_24dp);
Log.i("OROLA","IN ON CLICK");
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Log.i("OROLA","IN ON CLICK");
getActivity().onBackPressed();
}
});
getActionBar().setTitle("Select Slot");
我的活动就是这个
@Override
public void onBackPressed() {
FragmentManager fm = getFragmentManager();
if (fm.getBackStackEntryCount() > 0) {
fm.popBackStack();
} else {
super.onBackPressed();
}
}