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 ...
随机推荐
- 写一个背景渐变的TextView输入框
1:在res文件夹下新建一个drawble文件夹,并新建一个背景文件如writebg.xml <?xml version="1.0" encoding="utf-8 ...
- BZOJ 1642: [Usaco2007 Nov]Milking Time 挤奶时间( dp )
水dp 先按开始时间排序 , 然后dp. dp( i ) 表示前 i 个时间段选第 i 个时间段的最优答案 , 则 dp( i ) = max( dp( j ) ) + w_i ( 0 < j ...
- BZOJ 1355: [Baltic2009]Radio Transmission( kmp )
自己YY一下可以发现answer = n - fail[ n ] ------------------------------------------------------------------ ...
- thinkphp小技巧
if(IS_POST) _404("页面不存在",U("index")) //如果不是POST提交,则跳转到index.debug模 ...
- 条码知识之九:EAN-128条码(上)
EAN-128码,现称GS1-128码,是专用于GS1系统中的条码,可以标注商品的附加信息,在商品信息的标识.产品的跟踪与追溯中有广泛的用途. EAN-128码来自于CODE-128码,在字符集.条 ...
- 返回hash 类型的json
else{ $hash{$phone}="没有找到需要的验证码信息"; $c->render(json => \%hash );
- Hadoop Hive与Hbase整合+thrift
Hadoop Hive与Hbase整合+thrift 1. 简介 Hive是基于Hadoop的一个数据仓库工具,可以将结构化的数据文件映射为一张数据库表,并提供完整的sql查询功能,可以将sql语句 ...
- setuptools,easy_install使用
当需要安装第三方python包时,可能会用到easy_install命令.easy_install是由PEAK(Python Enterprise Application Kit)开发的setupto ...
- volley源代码解析(七)--终于目的之Response<T>
在上篇文章中,我们终于通过网络,获取到了HttpResponse对象 HttpResponse是android包里面的一个类.然后为了更高的扩展性,我们在BasicNetwork类里面看到.Volle ...
- DataTable 用linq分组查询
DataRow drt = null; var tlist = dt.Select("Atmbs LIKE '%" + d["Two_Code"] + &quo ...