虽然有点没看到但是留着以后会看的更明白的。
摘自:http://blog.csdn.net/chuchu521/article/details/8052855
xmlns:Android="http://schemas.android.com/apk/res/android的作用是
在使用到自定义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>
运行结果:
相关推荐
Android xmlns 的作用及其自定义实例详解 xmlns:Android=”http://schemas.android.com/apk/res/android的作用是: 这个是xml的命名空间,有了他,你就可以alt+/作为提示,提示你输入什么,不该输入什么,什么是对...
<merge xmlns:android=http://schemas.android.com/apk/res/android xmlns:tools=http://schemas.android.com/tools> <RelativeLayout android:id=@+id/wrapper_seekbar_indicator android:la
<?xml version="1.0" encoding="UTF-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_...android自定义弹出框,很实用的
我们知道,当系统控件并不能满足我们的需求时,我们就需要来创建自定义控件,主要有两种方法 (1)引入布局 下面来自定义一个控件,iPhone的...LinearLayout xmlns:android=http://schemas.android.com/apk/res/android
xmlns:swagpoints="http://schemas.android.com/apk/res-auto" android:id="@ id/seekbar_point" android:layout_width="match_parent" android:layout_height="340dp" android:layout_gravity="center" ...
xmlns:badboy="http://schemas.android.com/apk/res-auto" badboy自己随意写 2、使用自定义布局 //线型布局 android:layout_width="match_parent" android:layout_height="200dip" android:background="@...
<selector xmlns:android="http://schemas.android.com/apk/res/android"> <!--这里是对应点击之后,CheckBox的背景图--> <item android:drawable="@drawable/checkBtn_on" android:state_checked="true" android:...
首先来看一下效果图,如下所示: 其中进度条如下: 接下来说一说我的思路,上面的进度拖动条有自定义的Thumb,在Thumb正上方有一...RelativeLayout xmlns:android=http://schemas.android.com/apk/res/android andr
最近需要做一个app,需要用到tablayout实现顶部的滑动,用到了自定义item,不过没有用到tabitem,贴出来供大家学习,先看图吧,觉得满意的继续往下面看 具体代码实现: 我直接贴啦,能说的不多 主布局: fragment_...
本文实例讲述了Android编程实现自定义控件的方法。分享给大家供大家参考,具体如下: 很多时候Android常用的控件不能满足我们的需求,那么我们就需要自定义一个控件了。今天做了一个自定义控件的实例,来分享下。 ...
本文实例为大家分享了Android自定义View实现跟随手指移动的小兔子,供大家参考,具体内容如下 自定义的View实现跟随手指的小兔子 按前面的例子新创建一个project,再在project中新创建一个module 将需要的背景图和...
Android自定义照相机实现 近期小巫在学校有一个创新项目,也不是最近,是一个拖了很久的项目,之前一直没有去搞,最近因为要中期检查,搞得我跟小组成员一阵忙活,其实开发一款照相机软件并不太难,下面就是通过...
本文实例为大家分享了android自定义imageview实现圆角图片的具体代码,供大家参考,具体内容如下 自定义图片的属性,对图片进行圆角切割 实现效果图: (1)在activity_main.xml文件布局,非常简单 <?xml ...
<selector xmlns:android="http://schemas.android.com/apk/res/android"> <!-- 按下状态 --> <item android:state_pressed="true" android:drawable="@drawable/bg3" /> <!-- 普通无焦点状态 --> <item ...
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"> <item android:id="@+android:id/background" android:drawable="@drawable/xixi0" /> <item android:id="@+android:id/...
本文实例讲述了Android编程实现自定义title功能。分享给大家供大家参考,具体如下: 这里我在前面加了个logo,而且改变了title的背景和高度。 首先编写title的布局文件,title.xml: <?xml version=1.0 ...
自定义拍照会用到SurfaceView控件显示照片的预览区域,以下是布局文件: 两个TextView是用来显示提示信息和倒计时的秒数的 相关教程:Android开发从相机或相册获取图片裁剪 Android启动相机拍照并返回图片 <...
本文实例讲述了Android编程使用自定义shape实现shadow阴影效果的方法。分享给大家供大家参考,具体如下: 直接上xml文件, 并且附上相应的解析: <?xml version=1.0 encoding=utf-8?> <selector xmlns:android...
Android使用xml自定义图片实例详解 实现效果图: 白色圆角图片 bg_round_rectangle_white.xml <?xml version=1.0 encoding=utf-8?> <shape xmlns:android=http://schemas.android.com/apk/res/android ...