xmlns:android="http://schemas.android.com/apk/res/android的作用是
xmlns:android="http://schemas.android.com/apk/res/android的作用是
这个是xml的命名空间,有了他,你就可以alt+/作为提示,提示你输入什么,不该输入什么,什么是对的,什么是错的,也可以理解为语法文件。或者语法判断器什么的
这个主要作用是在运行的时候那些控件的属性都是通过它来识别的,如果上面你写错了,不会有任何问题,但是在运行的时候就会有问题,提示你没有指定宽度等什么。这个是不用联网的。
在使用到自定义View的xml布局文件中需要加入xmlns:前缀=http://schemas.android.com/apk/res/你的应用程序包路径.
下面是一个简单的例子:
结构图:

MyView.java
package kexc.myView;
import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.widget.TextView;
public class MyView extends TextView {
private String mString = "Welcome to Kesion's blog";
public MyView(Context context, AttributeSet attrs) {
super(context, attrs);
TypedArray a = context.obtainStyledAttributes(attrs,
R.styleable.MyView);
int textColor = a.getColor(R.styleable.MyView_textColor,
0XFFFFFFFF);
float textSize = a.getDimension(R.styleable.MyView_textSize, 36);
mString = a.getString(R.styleable.MyView_title);
setText(mString);
setTextSize(textSize);
setTextColor(textColor);
}
}
main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:test="http://schemas.android.com/apk/res/kexc.myView"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
/>
<kexc.myView.MyView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
test:title="wo shi text"
test:textSize="20px"
test:textColor="#fff"
/>
</LinearLayout>
属性文件 value/attrs.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<declare-styleable name="MyView">
<attr name="textColor" format="color"/>
<attr name="textSize" format="dimension" />
<attr name="title" format="string"/>
</declare-styleable>
</resources>
运行结果:

xmlns:android="http://schemas.android.com/apk/res/android的作用是的更多相关文章
- android 布局文件中xmlns:android="http://schemas.android.com/apk/res/android"
http://blog.163.com/benben_long/blog/static/199458243201411394624170/ xmlns:android="http://sch ...
- 添加xmlns:android="http://schemas.android.com/apk/res/android"的意思
http://www.cnblogs.com/lovely/archive/2013/01/17/2865192.html xmlns:android="http://schemas.and ...
- xmlns:android="http://schemas.android.com/apk/res/android 这句话的作用
xmlns:android="http://schemas.android.com/apk/res/android 有了这句话,你就可以alt+/作为提示,提示你输入什么,不该输入什么,什么 ...
- xmlns:android="http://schemas.android.com/apk/res/android" 是什么意思?
声明xml命名空间.xmlns意思为“xml namespace”.冒号后面是给这个引用起的别名.schemas是xml文档的两种约束文件其中的一种,规定了xml中有哪些元素(标签).元素有哪些属性及 ...
- 导入项目后,http://schemas.android.com/apk/res/android报错
1.复制出现红色字体的路径 2.File - Settings - Language & Frameworks - schemas and DtDs - 粘贴显红路径
- Unity编译Android的原理解析和apk打包分析
作者介绍:张坤 最近由于想在Scene的脚本组件中,调用Android的Activity的相关接口,就需要弄明白Scene和Activity的实际对应关系,并对Unity调用Android的部分原理进 ...
- Android 图片Bitmap,drawable,res资源图片之间转换
一.知识介绍 ①res资源图片是放在项目res文件下的资源图片 ②BitMap位图,一般文件后缀为BMP,需要编码器编码,如RGB565,RGB8888等.一种逐像素的显示对象,其执行效率高,但缺点也 ...
- Android为TV端助力 apk静默安装
转载请注明出处:http://blog.csdn.net/guolin_blog/article/details/47803149 之前有很多朋友都问过我,在Android系统中怎样才能实现静默安装呢 ...
- 【Android自学日记】【转】Android Fragment 真正的完全解析(下)
上篇博客中已经介绍了Fragment产生原因,以及一些基本的用法和各种API,如果你还不了解,请看:Android Fragment 真正的完全解析(上). 本篇将介绍上篇博客提到的:如何管理Frag ...
随机推荐
- NSOperationQueue和GCD的区别
使用NSOperationQueue用来管理子类化的NSOperation对象,控制其线程并发数目.GCD和NSOperation都可以实现对线程的管理,区别是 NSOperation和NSOpera ...
- Jsp中使用EL表达式对字符串进行操作
用fn函数:<%@ taglib prefix="fn" uri="http://Java.sun.com/jsp/jstl/functions" %&g ...
- MD5校验及其c实现
那么MD5校验是什么? 一般软件或者说文件都有自己的固定文件格式或者架构信息,说简单一点就是.”世界上没有完全相同的2片叶子” ,因为MD5是一种不可逆的加密算法. 那么对于某些网上公开下载的软件,视 ...
- nginx根据条件跳转+跳转规则
好的参考博文: nginx rewrite规则 自己写的时候参考这两个 Nginx 伪静态Rewrite,重定向Location配置总结(转) nginx rewrite规则语法 一.输入子目录跳转 ...
- Python学习之路——类
类: 类是将抽象的实物进行的划分. 在现实世界中如果我们将: 人类包含:男人.女人.孩子.老人等动物类包含:小猫.小狗.小兔子等 在代码世界中我也可以分类,例如将相同功能的代码放到一起,这就是分类. ...
- QT图片旋转
目前发现有两种方法,如下: 1.使用QPixmap的transformed函数旋转,这个函数默认是以图片中心为旋转点,不能随意设置旋转点,使用如下: QMatrix leftmatrix; leftm ...
- Windows Azure 社区新闻综述(#77 版)
欢迎查看最新版本的每周综述,其中包含有关云计算和 Windows Azure 的社区推动新闻.内容和对话.以下是本周的亮点. 文章.视频和博客文章 · 文章: Windows Azure 表存储简 ...
- BZOJ 1610: [Usaco2008 Feb]Line连线游戏
1610: [Usaco2008 Feb]Line连线游戏 Description Farmer John最近发明了一个游戏,来考验自命不凡的贝茜.游戏开始的时 候,FJ会给贝茜一块画着N (2 &l ...
- 解题报告 HDU1176 免费馅饼
免费馅饼 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submis ...
- TCP之超时和重传
RTT:往返时间: RTO:Retransmission Timeout即超时重传时间: 关键点在于:超时和重传间隔的策略,即怎样确定超时间隔和重传间隔: TCP中的四个定时器:2MSL定时器:重传 ...