AppCompat和EditText上强调不同的API不同、AppCompat、EditText、API

2023-09-06 15:02:29 作者:糖果屋の甜蜜

我试图让下划线线条颜色变化的EditText(验证,所以它必须能够在运行时更改)。我使用AppCompat做到这一点。问题是,在API> = 21,我看到的不是加粗版透明黑线(灰覆盖)。

I'm trying to make underline line color change for EditText (validation, so it must be able to change in runtime). I'm using AppCompat to do it. The problem is that on API >= 21, I see transparent black line (gray overlay), instead of bolded version.

如何使它等同于API 16?

How to make it the same as in API 16?

我用这个code改变色调:

I used this code to change tint:

    final Drawable originalDrawable = view.getBackground();
    final Drawable wrappedDrawable = DrawableCompat.wrap(originalDrawable);
    DrawableCompat.setTint(wrappedDrawable, Color.RED);
    setBackground(view,wrappedDrawable);

推荐答案

解决方案通过将这些线到我的主题发现:

Solution found by adding these lines to my theme:

    <item name="editTextStyle">@style/Base.V7.Widget.AppCompat.EditText</item>
    <item name="editTextBackground">@drawable/abc_edit_text_material</item>