I am trying to show toolbar along with the menu items in an activity. This works fine until I add databinding to the xml. I can not use setSupportActionBar(toolbar) at all after that. Here is my xml file activity_single_product.xml
<?xml version="1.0" encoding="utf-8"?>
<layout>
<data>
<variable name="product"
type="com.sales.models.ProductModel"/>
<variable name="glide" type="com.bumptech.glide.Glide" />
</data>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/activity_view_single_product"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.sales.SingleProductActivity"
android:background="@color/colorPrimary">
<LinearLayout
android:id="@+id/container_toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<include
android:id="@+id/tool"
layout="@layout/toolbar" />
<include
android:id="@+id/search_layout"
layout="@layout/search_layout" />
<View
android:layout_width="match_parent"
android:layout_height="5dp"
android:background="@drawable/drop_shadow_toolbar" />
</LinearLayout> <!-- Toolbar & Search bar-->
</RelativeLayout>
</layout>
The Activity :
private void initViews() {
binding = DataBindingUtil.setContentView(this, R.layout.activity_single_product); // ActivitySingleProductBinding
setSupportActionBar(binding.tool.toolbar);
binding.setProduct(product);
}
I have followed stackoverflow answer. This didn't help. Can anyone suggest?