Main Activity:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getSupportActionBar().setDisplayShowHomeEnabled(true);
getSupportActionBar().setDisplayUseLogoEnabled(true);
getSupportActionBar().setCustomView(R.layout.action_bar_layout);
getSupportActionBar().setDisplayShowCustomEnabled(true);
MedSectionFragment medSectionFragment = (MedSectionFragment)getSupportFragmentManager().findFragmentByTag("medSectionFragment");
if (medSectionFragment == null){
medSectionFragment = new MedSectionFragment();
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
transaction.add(android.R.id.content, medSectionFragment, "medSectionFragment");
// transaction.addToBackStack(null);
transaction.commit();
}
}
First Fragment:
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle saveInstanceState){
//Inflate the fragment layout file
ViewGroup rootView=(ViewGroup)inflater.inflate(R.layout.med_sections_list, container, false);
}
Second Fragment:
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle saveInstanceState) {
//Inflate the fragment layout file
ViewGroup rootView = (ViewGroup) inflater.inflate(R.layout.official_name_list, container, false);
}
after the transition from one fragment (categories) to another (sub-categories) we have listview with actionbar. its true.
But when I transition to the third fragment (detail information)
public class DetailMedicineFragment extends Fragment {
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle saveInstanceState) {
ViewGroup rootView = (ViewGroup) inflater.inflate(R.layout.detail_medicine_fragment, container, false);
return rootView;
}
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
Toolbar toolbar = (Toolbar)getActivity().findViewById(R.id.mToolbar);
((AppCompatActivity) getActivity()).setSupportActionBar(toolbar);
}
an error occurs
java.lang.IllegalStateException: This Activity already has an action bar supplied by the window decor. Do not request Window.FEATURE_SUPPORT_ACTION_BAR and set windowActionBar to false in your theme to use a Toolbar instead. at android.support.v7.app.AppCompatDelegateImplV7.setSupportActionBar(AppCompatDelegateImplV7.java:198) at android.support.v7.app.AppCompatActivity.setSupportActionBar(AppCompatActivity.java:99) at ua.edu.sumdu.medmaterialdesign.DetailMedicineFragment.onActivityCreated(DetailMedicineFragment.java:41) at android.support.v4.app.Fragment.performActivityCreated(Fragment.java:1970) at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1092) at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1248) at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:738) at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1613) at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:517) at android.os.Handler.handleCallback(Handler.java:739) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:211) at android.app.ActivityThread.main(ActivityThread.java:5389) at java.lang.reflect.Method.invoke(Native Method) at java.lang.reflect.Method.invoke(Method.java:372) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1020) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:815)
application style
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>