zoukankan      html  css  js  c++  java
  • theme- 自定义控件属性

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

    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>
  • 相关阅读:
    linux addr2line 定位so库崩溃位置
    转:关于Android机型适配这件小事儿
    转:android studio 改编译区背景色
    转:ios review推送与执行
    k2pdfopt下载页
    转:让kindle更好的支持pdf
    转:各种文本格式转换的网站
    转: iOS崩溃堆栈符号表使用与用途
    转: 腾讯Bugly干货分享:Android应用性能评测调优
    转: git的图文使用教程(巨详细)
  • 原文地址:https://www.cnblogs.com/zhangshuli-1989/p/zhangshuli_edittext_150312134.html
Copyright © 2011-2022 走看看