I am having a problem with this code. When I run it in kitkat, it prompts an unhandled exception
Android.Views.InflateException : Binary XML file line #1: Error inflating class toolbar
BTW: I also used
< android.support.v7.widget.Toolbar >
...
< / android.support.v7.widget.Toolbar >
as suggested in other questions but it's still the same.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!--Error came from this toolbar-->
<Toolbar
android:minHeight="30dp"
android:layout_width="match_parent"
android:layout_height="30dp"
android:background="@color/lime"
android:id="@+id/toolbar"
android:elevation="6dp">
<TextView
android:text="BranchName"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:layout_marginRight="155dp"
android:id="@+id/branchName"
android:textColor="#000000" />
<TextView
android:text="Logout"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:id="@+id/logout"
android:layout_marginRight="5dp"
android:elevation="8dp"
android:textColor="#000000" />
</Toolbar>
</LinearLayout>
it is included from other .axml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:minWidth="25px"
android:minHeight="25px"
android:background="#fafafa"
android:weightSum="100">
<!--Toolbar was called from here by include-->
<include
layout="@layout/ToolbarLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<LinearLayout
android:orientation="horizontal"
android:minWidth="25px"
android:minHeight="25px"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/olive"
android:id="@+id/linearLayout1"
android:padding="5dp">
<ImageButton
android:src="@drawable/backB"
android:layout_width="30dp"
android:layout_height="30dp"
android:background="@color/olive"
android:id="@+id/backButton"
android:scaleType="fitCenter" />
<LinearLayout
android:orientation="vertical"
android:minWidth="25px"
android:minHeight="25px"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/linearLayout3"
android:layout_marginLeft="-30dp">
<TextView
android:text="My Orders"
android:textAppearance="? android:attr/textAppearanceLarge"
android:textColor="@color/white"
android:id="@+id/textView1"
android:layout_gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>
<!--Other codes are not related anymore to the issue-->
</LinearLayout>
I researched a lot but I think other issues regarding InflateException are not related to my issue. What should I fix here?
After lots of testings, I made it :D Thanks to https://devblogs.microsoft.com/xamarin/android-tips-hello-appcompatactivity-goodbye-actionbaractivity/
here are my changes
I added nuget xamarin.android.support.v7.appCompat and it's dependencies. (since xamarin don't have gradle)
*in activity.cs:
-using Android.Support.V7.App;
-from public class OrdersActivity : Activity
-to public class OrdersActivity : AppCompatActivity
*in style.xml
-from style name="MyTheme" parent="@android:style/Theme.Material.Light.DarkActionBar"
-to style name="MyTheme" parent="Theme.AppCompat.Light.DarkActionBar"
*in ToolbarLayout.axml
-from
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<Toolbar
android:minHeight="30dp"
android:layout_width="match_parent"
android:layout_height="30dp"
android:background="@color/lime"
android:id="@+id/toolbar"
android:elevation="6dp">
...
</Toolbar>
</LinearLayout>
-to
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!--I change it back to android.support.v7.widget-->
<android.support.v7.widget.Toolbar
android:minHeight="30dp"
android:layout_width="match_parent"
android:layout_height="30dp"
android:background="@color/lime"
android:id="@+id/toolbar"
android:elevation="6dp">
...
</android.support.v7.widget.Toolbar>
</LinearLayout>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With