【问题标题】:Change underline color for Custom AutoCompleteTextView更改自定义 AutoCompleteTextView 的下划线颜色
【发布时间】:2018-08-04 15:45:52
【问题描述】:

我想将自定义AutoCompleteTextView的下划线颜色更改为下面电话号码下的蓝色为其他颜色,并去除下划线上方约2dp的空间(请注意垂直线两端)。

我在网上找不到问题的解决方案。

在创建自定义 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空间是什么意思??

标签: android xamarin xamarin.android autocompletetextview


【解决方案1】:

使用android:backgroundTint 更改MyAutoCompleteTextView 的颜色。喜欢

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

为了更加可定制,请将 MyAutoCompleteTextView 的父类更改为 AppCompatAutoCompleteTextView 而不是 AutoCompleteTextView

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-09-15
    • 2015-04-08
    • 2017-07-23
    • 1970-01-01
    • 2017-12-18
    • 2021-04-30
    • 2021-03-10
    相关资源
    最近更新 更多