更改自定义AutoCompleteTextView下划线颜色

3

我想要修改自定义的AutoCompleteTextView下划线的颜色,比如将下方电话号码下面的蓝色改为其他颜色,并且去掉上方约2dp的空间(请注意两端的竖线)。

enter image description here

我无法在网上找到这个问题的解决方案。
在创建自定义AutoCompleteTextView之前,我通过colors.xml中的重点颜色更改了内置AutoCompleteTextView的下划线颜色,如下所示。
<resources>
        ...
  <color name="accent">#206DDA</color>
...
</resources>

然而,当自定义的AutoCompleteTextView替代内置的AutoCompleteTextView时,下划线颜色使用默认颜色,如上图所示。
我尝试了以下方法,但不起作用: 下面是styles.xml:
<style name="Autocomplete" parent="Widget.AppCompat.Light.AutoCompleteTextView">    
    <item name="colorControlActivated">@color/primary</item>
  </style>

下面是activity.xml:

<android.support.design.widget.TextInputLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">
            <MyAutoCompleteTextView             
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:hint="Phone number"
                android:completionThreshold="1"
                android:maxLines="1"
                android:inputType="text"
                android:imeOptions="actionNext"
                android:theme="@style/Autocomplete"
                android:layout_marginLeft="5dp"
                android:layout_marginRight="5dp" />
        </android.support.design.widget.TextInputLayout>

以下是我的AutoCompleteTextView:
public class MyAutoCompleteTextView: AutoCompleteTextView
        {
            public MyAutoCompleteTextView(Context context, IAttributeSet attrs)
               : base(context, attrs)
            {
            }

            public override bool EnoughToFilter()
            {
                return true;
            }      
        }

将主题设置为TextInputLayout。另外,去掉2dp的空间是什么意思? - sanjeev
1个回答

0

使用android:backgroundTint来改变MyAutoCompleteTextView的颜色。例如:

<MyAutoCompleteTextView             
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    .......
    android:backgroundTint="#FF0000" />

为了使其更具可定制性,将MyAutoCompleteTextView的父类更改为AppCompatAutoCompleteTextView而不是AutoCompleteTextView

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接