我遇到此代码的问题。当我在kitkat中运行它时,它会提示未处理的异常
Android.Views.InflateException:二进制XML文件行#1:错误膨胀类工具栏
BTW:我也用过
< android.support.v7.widget.Toolbar>
...
< / android.support.v7.widget.Toolbar>
正如其他问题所述,但它仍然是相同的。
<?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>
它包含在其他.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>
我研究了很多,但我认为有关InflateException的其他问题与我的问题无关。 我应该在这里解决什么?
答案 0 :(得分:5)
经过大量的测试,我做到了:D 谢谢 https://blog.xamarin.com/android-tips-hello-appcompatactivity-goodbye-actionbaractivity/
这是我的更改
我添加了nuget xamarin.android.support.v7.appCompat及其依赖项。 (因为xamarin没有gradle)
* in activity.cs:
- 使用Android.Support.V7.App;
- 来自公共类OrdersActivity:Activity
- 公共类OrdersActivity:AppCompatActivity
* in style.xml
-from style name =“MyTheme”parent =“@ android:style / Theme.Material.Light.DarkActionBar”
-style style =“MyTheme”parent =“Theme.AppCompat.Light.DarkActionBar”
*在ToolbarLayout.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">
<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>