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. javaweb学习路之一--web项目搭建

    概述: 工作闲暇时间想要自己搭建一个web项目玩玩,没想到大半天才弄了一个springMVC+mybatis的网站,简直菜的不行,以下记录所有的步骤加深印象 使用环境 1.jdk1.8 2.maven ...

  2. Enze fifth day(循环语句2)

    又是新的一周开始了,我还在云和学院继续学习.因为想要急切的想学会更多的知识,所以我有些急.可是我越急就越容易出错,这应该就是所谓的欲速则不达吧.这一周,我要重新把控好自己的一切,尽我最大的努力来学习! ...

  3. SQL 注入与防御实例

    注入 1. 创建存储 USE TSQL2012; GO IF OBJECT_ID('Sales.ListCustomersByAddress') IS NOT NULL DROP PROCEDURE ...

  4. Visual Studio Tools for Unity安装及使用

    Visual Studio Tools for Unity安装及使用 转载自:CSDN 晃了一下,10.1到现在又过去两个月了,这两个月什么也没有学,整天上班下班,从这周末开始拾起unity,为了年后 ...

  5. Arduino 跷跷板(2016-01-04)

    前言这是参加社区活动,用赠送的 LilyPad 来做小实验,也体验了一把艺术的LilyPad!本来是申请 nano 的,不知道怎么的就出错啦,申请成 LilyPad 了,这个实验应该用 nano 比较 ...

  6. 2013 Changsha Regional 一样的木板一样的气球

    气球:      木板:   比赛现场: 场外: 曲线....  除了第一题出的太慢了,总体比成都好了很多.... 自此,今年两铜收场,再接再厉,明年要有更好的成绩.

  7. ViewFilpper

    package com.example.suneyaenews; import java.util.ArrayList; import java.util.HashMap; import java.u ...

  8. YIi配置debug工具、yii配置gii工具

    $config['bootstrap'][] = 'debug';$config['modules']['debug'] = [ 'class'=>'yii\debug\Module', 'al ...

  9. QQ对话代码

    <li> <strong class="QQ">客服QQ</strong> <span> <a href="mqqw ...

  10. Tortoisegit 记住用户名和密码

    Tortoisegit 记住用户名和密码方法: [Windows系统] 当你配置好git后,在 C:\Documents and Settings\Administrator\ 目录下有一个  .gi ...