I am trying to show both the title using setTitle and the custom view in my toolbar.
I do not see it as an action bar, and not as something more.
I add headers and custom view in Java
toolbar = (Toolbar) view.findViewById(R.id.toolbar); if (title != null) { toolbar.setTitle(title); toolbar.setTitleTextColor(getResources().getColor(android.R.color.white)); } if (subtitle != null) { toolbar.setSubtitle(subtitle); toolbar.setSubtitleTextColor(getResources().getColor(android.R.color.white)); } // Add switch view to toolbar View switchView = LayoutInflater.from(getActivity()) .inflate(R.layout.device_list_switch, null); toolbar.addView(switchView);
xml for my switch view
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@android:color/holo_blue_bright"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignBottom="@+id/discoverable" android:layout_alignParentBottom="true" android:layout_alignTop="@+id/discoverable" android:layout_toLeftOf="@+id/discoverable" android:layout_toStartOf="@+id/discoverable" android:gravity="center" android:text="@string/discoverable_switch_label" android:textColor="@android:color/white" /> <Switch android:id="@+id/discoverable" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_alignParentEnd="true" android:layout_alignParentRight="true" android:layout_marginLeft="@dimen/discoverable_switch_margin_left" android:layout_marginStart="@dimen/discoverable_switch_margin_left"/> </RelativeLayout>
What happens is that RelativeLayout fills the entire area of ββthe toolbar, and the title is not displayed.
Any ideas?
source share