0

I want to use one toolbar across the Application. But don't want to include it in a layout. Because I have a different hierarchy of fragment and activity. I wish to do an operation of setting of the action bar in base activity only. I tried it with inflating toolbar view and then setting it to action bar. I can see it in view hierarchy, but it is not actually showing on the screen, also not giving any error.

mCustomActionBarView = (Toolbar) getLayoutInflater().inflate(R.layout.application_action_bar, null, true);

mCustomActionBarView.setLayoutParams(new ActionBar.LayoutParams(ActionBar.LayoutParams.MATCH_PARENT, (int) getResources().getDimension(R.dimen.width_action_bar)));

setSupportActionBar(mCustomActionBarView);

BaseActivity is extending AppCompatActivity.

cakan
  • 2,099
  • 5
  • 32
  • 42
Nilesh
  • 237
  • 1
  • 3
  • 13
  • Does it necessary to add toolbar in layout wherever you want to show? if so then I have to add it on every screen of activity. – Nilesh Jan 19 '16 at 07:56
  • Have you tried MaterialToolbar library, it simplifies the toolbar management for single activity with fragments applications [MaterialToolbar on Github](https://github.com/Shyri/MaterialToolbar) – Shyri Jan 19 '16 at 09:17
  • I walk through library . They created one view "MaterialToolbar" and adding layout to the that id ("MaterialToolbar"). Ultimately they are adding toolbar layout to view and then action bar. I wish to separate layout for "Toolbar" and inflating it and adding to action bar . I don't want to add layout file in any of activity or layout – Nilesh Jan 19 '16 at 10:10

0 Answers0