码迷,mamicode.com
首页 > 其他好文 > 详细

自定义View的ToolBar布局报错Error:(2) No resource identifier found for attribute 'context' in package 'c

时间:2017-07-21 17:14:16      阅读:143      评论:0      收藏:0      [点我收藏+]

标签:code   test   代码   布局文件   layout   port   view   定义   androi   

这是由于你的自定义xmlns出错,

先上代码:

出错的布局文件

<android.support.v4.widget.DrawerLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/apk/res-auto"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="ca.sd.zsl.toolbartest.MainActivity">

改好的布局文件:

<android.support.v4.widget.DrawerLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.ca.sd.zsl.toolbartest"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="ca.sd.zsl.toolbartest.MainActivity">

清单文件

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="ca.sd.zsl.toolbartest">

自定义View界面时,命名空间需要自己定义,就是xmlns属性,首先Android开头的是系统自带的,你的各种系统自带空间就是他控制,接下来就是我们自己的命名空间了,

我给它取名tool,名字你任意取,然后Android后面要紧跟你的包名,加黑处为改动处

自定义View的ToolBar布局报错Error:(2) No resource identifier found for attribute 'context' in package 'c

标签:code   test   代码   布局文件   layout   port   view   定义   androi   

原文地址:http://www.cnblogs.com/zhoushenglei/p/7218210.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!