xmlns:android="http://schemas.android.com/apk/res/android的作用是

这个是xml的命名空间,有了他,你就可以alt+/作为提示,提示你输入什么,不该输入什么,什么是对的,什么是错的,也可以理解为语法文件。或者语法判断器什么的
这个主要作用是在运行的时候那些控件的属性都是通过它来识别的,如果上面你写错了,不会有任何问题,但是在运行的时候就会有问题,提示你没有指定宽度等什么。这个是不用联网的。
 
Android 自定义的xmlns其实很简单,语法规则是:

在使用到自定义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的作用是的更多相关文章

  1. android 布局文件中xmlns:android="http://schemas.android.com/apk/res/android"

    http://blog.163.com/benben_long/blog/static/199458243201411394624170/ xmlns:android="http://sch ...

  2. 添加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 ...

  3. xmlns:android="http://schemas.android.com/apk/res/android 这句话的作用

    xmlns:android="http://schemas.android.com/apk/res/android 有了这句话,你就可以alt+/作为提示,提示你输入什么,不该输入什么,什么 ...

  4. xmlns:android="http://schemas.android.com/apk/res/android" 是什么意思?

    声明xml命名空间.xmlns意思为“xml namespace”.冒号后面是给这个引用起的别名.schemas是xml文档的两种约束文件其中的一种,规定了xml中有哪些元素(标签).元素有哪些属性及 ...

  5. 导入项目后,http://schemas.android.com/apk/res/android报错

    1.复制出现红色字体的路径 2.File - Settings - Language & Frameworks - schemas and DtDs - 粘贴显红路径

  6. Unity编译Android的原理解析和apk打包分析

    作者介绍:张坤 最近由于想在Scene的脚本组件中,调用Android的Activity的相关接口,就需要弄明白Scene和Activity的实际对应关系,并对Unity调用Android的部分原理进 ...

  7. Android 图片Bitmap,drawable,res资源图片之间转换

    一.知识介绍 ①res资源图片是放在项目res文件下的资源图片 ②BitMap位图,一般文件后缀为BMP,需要编码器编码,如RGB565,RGB8888等.一种逐像素的显示对象,其执行效率高,但缺点也 ...

  8. Android为TV端助力 apk静默安装

    转载请注明出处:http://blog.csdn.net/guolin_blog/article/details/47803149 之前有很多朋友都问过我,在Android系统中怎样才能实现静默安装呢 ...

  9. 【Android自学日记】【转】Android Fragment 真正的完全解析(下)

    上篇博客中已经介绍了Fragment产生原因,以及一些基本的用法和各种API,如果你还不了解,请看:Android Fragment 真正的完全解析(上). 本篇将介绍上篇博客提到的:如何管理Frag ...

随机推荐

  1. Java多线程之synchronized(一)

    在上节中已经说过了“非线程安全”是如何出现的,链接如下:http://www.cnblogs.com/chentong/p/5650137.html,那么怎么解决“非线程安全”问题呢,只需要在两个线程 ...

  2. flash builder 4 编译器参数

    accessible=true|false 是否具有可理解性(如为残疾人提供方便的性能) actionscript-file-encoding | 设置文件编码,如Shitf_JIS advanced ...

  3. Canvas使用渐变之-线性渐变详解

    在canvas里面,除了使用纯色,我们还能把填充和笔触样式设置为渐变色:线性渐变和径向渐变. 线性渐变 createLinearGradient(x0,y0,x1,y1)  返回 CanvasGrad ...

  4. SpringMVC请求访问不到静态文件解决方式

    如何你的DispatcherServlet拦截"*.do"这样的有后缀的URL,就不存在访问不到静态资源的问题. 如果你的DispatcherServlet拦截"/&qu ...

  5. 关于MyEclipse启动时的插件启动(Maven4MyEclipse)

    在myEclipse的应用中有许多插件在开发的时候都用不到,那么,这些插件在启动myEclipse的时候一起启动的越少越好了 Maven4Myeclipse update 每当启动myEclipse的 ...

  6. OCP-1Z0-053-V13.02-712新题

       Why does the number of blocks for the table remain the sale after the shrink operation? A.Because ...

  7. js中设置setInterval的注意点

    <html> <head> <meta http-equiv="Content-Type" content="text/html; char ...

  8. Android各种效果集合

    QQ侧滑风格:http://www.cnblogs.com/lichenwei/p/4111252.html,通过继承HorizontalScrollView类来实现的.

  9. django 基础入门(二)

    一.关于数据库 1.首先django 1.9以上等版本不支持pymysql,因此需要做一些调整. 比如在settings.py 加入一段代码: import pymysql pymysql.insta ...

  10. asp.net 页面执行过程

    Application_BeginRequest Application_AuthenticateRequest Application_AuthorizeRequest Application_Re ...