今天想要在一个控件中增加自己的一条属性,具体步骤如下

1.在frameworks/base/core/res/res/values/attr中注册属性

因为我们希望增加的属性是在AutoCompleteTextView中,所以我们添加如下

 <declare-styleable name="AutoCompleteTextView">
<!-- Defines the marginright in the drop down menu. -->
<attr name="dropDownListItemPaddingRight" format="dimension" />
<!-- Defines the hint displayed in the drop down menu. -->
<attr name="completionHint" format="string" />
<!-- Defines the hint view displayed in the drop down menu. -->
<attr name="completionHintView" format="reference" />
<!-- Defines the number of characters that the user must type before
completion suggestions are displayed in a drop down menu. -->
<attr name="completionThreshold" format="integer" min="1" />
<!-- Selector in a drop down list. -->
<attr name="dropDownSelector" format="reference|color" />
<!-- Amount of pixels by which the drop down should be offset vertically. -->
<attr name="dropDownVerticalOffset" format="dimension" />
<!-- Amount of pixels by which the drop down should be offset horizontally. -->
<attr name="dropDownHorizontalOffset" format="dimension" />
<!-- View to anchor the auto-complete dropdown to. If not specified, the text view itself
is used. -->
<attr name="dropDownAnchor" format="reference" />
</declare-styleable name="AutoCompleteTextView">

2.代码中引用

主要是在AutoCompleteTextView.java

        TypedArray a =
context.obtainStyledAttributes(
attrs, com.android.internal.R.styleable.AutoCompleteTextView, defStyle, 0);
mPopupMargnRight = (int) a.getDimension(R.styleable.AutoCompleteTextView_dropDownListItemPaddingRight, 0.0f);

3.style 中设定属性值

 <style name="Widget.Funui.AutoCompleteTextView" parent="Widget.AutoCompleteTextView">
<item name="android:dropDownSelector">@android:drawable/list_selector_funui</item>
<item name="android:popupBackground">@android:drawable/menu_dropdown_panel_funui</item>
<item name="android:dropDownListItemPaddingRight">13dp</item>
</style>

theme- 自定义控件属性的更多相关文章

  1. c#自定义控件属性面板及选择资源设置

    博客转移到 http://jacean.github.io/ 继续分享编程经验 因为要做流体布局,但两个控件没办法组合,就做自定义控件.这个控件需要一个text设置文本,一个pic设置图片显示,图片通 ...

  2. Qt编写自定义控件属性设计器

    以前做.NET开发中,.NET直接就集成了属性设计器,VS不愧是宇宙第一IDE,你能够想到的都给你封装好了,用起来不要太爽!因为项目需要自从全面转Qt开发已经6年有余,在工业控制领域,有一些应用场景需 ...

  3. winform 自定义控件属性在属性面板中显示

    Jan.David Nothing is impossible, the word itself says 'I'm possible'!" — Audrey Hepburn winform ...

  4. c# 用户控件,usercontrol,自定义控件属性

    1.C#用户控件的使用 2.拖动添加:画面上如需多个usercontrol,添加TableLayoutPanel,然后在工具箱中找到usercontrol,拖到相应框中 3.代码添加:主窗口中有多个T ...

  5. android自定义控件(1)-自定义控件属性

    那么还是针对我们之前写的自定义控件:开关按钮为例来说,在之前的基础上,我们来看看有哪些属性是可以自定义的:按钮的背景图片,按钮的滑块图片,和按钮的状态(是开还是关),实际上都应该是可以在xml文件中直 ...

  6. Xcode 属性面板添加自定义控件属性

    让自定义控件像原生控件一样可以在属性面板配置参数,Apple文档传送 直接上效果图,根据

  7. activity theme parent 属性浅析

    在AndroidManifest.xml文件中,可以对每一个Activity设置android:themetheme的设置 可以设置为系统自带的格式,也可以自定义格式. A: 系统自带格式 1.and ...

  8. 安卓自定义View(一)自定义控件属性

    自定义View增加属性第一步:定义属性资源文件 在/res/values 文件夹下建立"Values XML layout",按照如下定义一个textview的属性 <?xm ...

  9. [转]C#自定义控件属性与行为

    原文链接:http://blog.csdn.net/a237428367/article/details/5926445 控件应该定义属性而不是公共字段,因为可视化设计器在属性浏览器中显示属性,而不显 ...

  10. android自定义控件属性

    有两种方法为自定义的控件设置属性 . 来自为知笔记(Wiz)

随机推荐

  1. IDEA修改当前工程jdk版本

    1.ctrl+shift+alt+s 2.根据实际情况修改jdk版本

  2. EXPIREAT

    EXPIREAT key timestamp EXPIREAT 的作用和EXPIRE类似,都用于为key设置生存时间. 不同在于EXPIREAT命令接受都时间参数是UNIX时间戳(unix times ...

  3. [问题]HDOJ1032 The 3n + 1 problem

    http://acm.hdu.edu.cn/showproblem.php? pid=1032 这题能够用暴力求解.求出在[ni,nj]之间全部数字产生的最大值. 通过观察能够知道,当nk靠近nj的时 ...

  4. 关于post请求“CAUTION: Provisional headers are shown”【转】

    在POST请求中偶尔会出现"CAUTION: Provisional headers are shown" 这个警告的意思是说:请求的资源可能会被(扩展/或其它什么机制)屏蔽掉. ...

  5. vijos - P1176奇怪的数列 (递归 + 找规律)

    P1176奇怪的数列 Accepted 标签:[显示标签] 背景 一天.学军数学小组的成员遇到了一个奇怪的数列,正巧信息小组的你碰到了他们. 于是他们把这个数列展示给你-- 描写叙述 这个数列是这种: ...

  6. .ds_store是什么文件

    .ds_store是什么文件 .DS_Store是Mac OS保存文件夹的自定义属性的隐藏文件,如文件的图标位置或背景色,相当于Windows的desktop.ini. 1,禁止.DS_store生成 ...

  7. asp.net 关于cookie的操作

    一.无子键或单级cookie 读写(1).写入: 第一种 HttpCookie cookie=new HttpCookie("User"); cookie.Value=" ...

  8. 海康录像机 POE 输送距离 实验

    条件:网线 使用亨通  (移动公司使用网线) 测试一:   网线  为130米    白天       摄像头正常录像 电压      3,7号线                 19.6V 测试二: ...

  9. 如何建立远程桌面连接(XP、Vista、Win7)

    如何建立远程桌面连接(XP.Vista.Win7) 要求: 1:对方即你要连的机器必须要允许远程桌面连接,操作系统一般是winXP(单用户)和win2003server(多用户),具体设置:右击我的电 ...

  10. JS对象继承与原型链

    1.以复制方式实现的继承 1.1浅拷贝 基本类型的复制 var parent = { lanage: "chinese" } var child = { name: "x ...