码迷,mamicode.com
首页 > 其他好文 > 详细

theme- 自定义控件属性

时间:2015-03-12 14:40:21      阅读:130      评论:0      收藏:0      [点我收藏+]

标签:

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

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- 自定义控件属性

标签:

原文地址:http://www.cnblogs.com/zhangshuli-1989/p/zhangshuli_edittext_150312134.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!