I have a toolbar in my xml file, with no child views defined in it. I want to add a TextView on exact location of default title in toolbar when we call setSupportActionBar(toolbar)
. On particular events, I like to fade in or out these two views in case of particular events.
I tried to do the following in onCreate()
of the activity, but nothing is visible except the default title in toolbar.
TextView tv = new TextView(this);
tv.setLayoutParams(toolbarTitle.getLayoutParams());
tv.setHeight(toolbarTitle.getHeight());
tv.setWidth(toolbarTitle.getWidth());
tv.setText("Other Title");
tv.setLeft(toolbarTitle.getLeft());
toolbar.addView(tv);
I also tried to add a RelativeLayout inside the toolbar with width and height set to match parent, but this time, default title TextView of toolbar disappears.
How can add another TextView on exact location of default title TextView in toolbar?