更改自定义 AutoCompleteTextView 的下划线颜色
Change underline color for Custom AutoCompleteTextView
我想把一个自定义AutoCompleteTextView
的下划线颜色改成其他颜色Phone下的蓝色,然后把下划线上面的space去掉2dp左右(请注意垂直线 1 的两端)。
我在网上找不到问题的解决方案。
在创建自定义 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;
}
}
使用android:backgroundTint
改变MyAutoCompleteTextView
的颜色。喜欢
<MyAutoCompleteTextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
.......
android:backgroundTint="#FF0000" />
为了提高可定制性,将 MyAutoCompleteTextView
的父级 class 更改为 AppCompatAutoCompleteTextView
而不是 AutoCompleteTextView
我想把一个自定义AutoCompleteTextView
的下划线颜色改成其他颜色Phone下的蓝色,然后把下划线上面的space去掉2dp左右(请注意垂直线 1 的两端)。
我在网上找不到问题的解决方案。
在创建自定义 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;
}
}
使用android:backgroundTint
改变MyAutoCompleteTextView
的颜色。喜欢
<MyAutoCompleteTextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
.......
android:backgroundTint="#FF0000" />
为了提高可定制性,将 MyAutoCompleteTextView
的父级 class 更改为 AppCompatAutoCompleteTextView
而不是 AutoCompleteTextView