在布局文件里添加toolbar时出现的错误error: Error parsing XML: unbound prefix

来源:互联网 发布:三菱flrd 数据读出 编辑:程序博客网 时间:2024/06/05 02:10
<span style="font-family: Arial, Helvetica, sans-serif; background-color: rgb(255, 255, 255);">        最近要做一个关于小学科学的数字化实验应用,由于ActionBar已经不建议使用(在代码上被画了横线),于是改用Android 5.0新出的ToolBar。要使用ToolBar,就要自己在布局里添加一个ToolBar控件。下面是要加入的ToolBar代码。</span>
<android.support.v7.widget.Toolbar        android:id="@+id/toolbar"        app:title="@string/app_name"        app:subtitle="@string/app_subtitle"        app:navigationIcon="@drawable/home_ico"        android:layout_height="wrap_content"        android:minHeight="?attr/actionBarSize"        android:layout_width="match_parent"        android:background="?attr/colorPrimary"/>

然后就报错:

error: Error parsing XML: unbound prefix


解决方法是:

android:id="@+id/toolbar"

下面添加一个属性:

xmlns:app="http://schemas.android.com/apk/res/com.example.toolbardemo"
加入布局的toolbar为

<android.support.v7.widget.Toolbar        android:id="@+id/toolbar"        xmlns:app="http://schemas.android.com/apk/res/com.example.toolbar"        app:title="@string/app_name"        app:subtitle="@string/app_subtitle"        app:navigationIcon="@drawable/home_ico"        android:layout_height="wrap_content"        android:minHeight="?attr/actionBarSize"        android:layout_width="match_parent"        android:background="?attr/colorPrimary"/>

至此错误消失。


0 0
原创粉丝点击