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

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. 【Codeforces Round #421 (Div. 2) B】Mister B and Angle in Polygon

    [题目链接]:http://codeforces.com/contest/820/problem/B [题意] 给你一个正n边形; 然后让你在这正n边行中选3个点,组成一个角; 找出角的大小和所给的角 ...

  2. Spring Cloud学习笔记【八】服务网关 Zuul(过滤器)

    在上篇文章中我们了解了 Spring Cloud Zuul 作为网关所具备的最基本功能:路由(Router),下面我们将关注 Spring Cloud Zuul 的另一核心功能:过滤器(Filter) ...

  3. sql server 2000 自动收缩数据库大小

    转载.......http://mars968.blog.163.com/blog/static/7400033200941642356258/ SQLServer2000压缩日志及数据库文件     ...

  4. CKEditor高级编辑器

    是否感觉后台分类描写叙述信息.商品描写叙述信息以及文章描写叙述信息 编写时很的不方便?有时候会将word的格式也复制过来了?那这个插件就比較适合了. 本插件使用CKEditor最新版本号,复制过来的内 ...

  5. 大型网站架构之JAVA中间件

    中间件就是在大型网站中,帮助各子模块间实现互相访问,消息共享或统一访问等功能的软件产品.常见的有: 远程服务框架中间件:主要解决各子模块之间互相访问的问题. 消息队列中间件:主要解决各子模之间消息共享 ...

  6. VS 2015支持C语言和C++程序

    先要安装C++的相关支持控件! 然后就可以使用VS编写C++或者C程序了. 默认支持的是C++,将后缀名改为C就是支持C了. 学习数据结构算法之类的,就可以通过VS来学习了. 安装 新建C++项目 C ...

  7. The method getDispatcherType() is undefined for the type HttpServletRequest错误解决方法

    使用Eclipse Luna版本,jdk1.7和tomcat8.0开发JAVA EE应用.写一个简单的JSP部署后访问报JSP编译错误,具体错误信息如下: The method getDispatch ...

  8. 16个ASP.NET MVC扩展点【附源码】

    转载于:http://www.cnblogs.com/wupeiqi/p/3570445.html 1.自定义一个HttpModule,并将其中的方法添加到HttpApplication相应的事件中! ...

  9. 温习 socket http tcp

    Socket是一个接口,可以实现TCP或者UDP的传输HTTP是协议 资料: 1.TCP/IP连接 手机能够使用联网功能是因为手机底层实现了TCP/IP协议,可以使手机终端通过无线网络建立TCP连接. ...

  10. react-native使用androidstudio时,安卓模拟器reload菜单界面显示快捷键ctrl+M;

    react-native使用androidstudio时,安卓模拟器reload菜单界面显示快捷键ctrl+M: