在android studio 4.1.x的新版本中聚焦时,更改EditText背景基线颜色
在旧版本的android studio中,当您关注所需的EditText时,可以通过更改colors.xml中的在android studio 4.1.x的新版本中聚焦时,更改EditText背景基线颜色,android,android-edittext,material-design,background-color,Android,Android Edittext,Material Design,Background Color,在旧版本的android studio中,当您关注所需的EditText时,可以通过更改colors.xml中的@color/ColorAccent来更改基线和提示颜色。但在新版Android Studio v4.1.1中,colors.xml中缺少colorAccent。这些元素在themes.xml中的颜色为@color/purple_500,如下图所示: 我认为在新材料设计中,动作栏和编辑文本的颜色必须相同。现在我想在不更改actionbar颜色的情况下更改聚焦的EditText颜色。
@color/ColorAccent
来更改基线和提示颜色。但在新版Android Studio v4.1.1中,colors.xml中缺少colorAccent。这些元素在themes.xml中的颜色为@color/purple_500
,如下图所示:
我认为在新材料设计中,动作栏和编辑文本的颜色必须相同。现在我想在不更改actionbar颜色的情况下更改聚焦的EditText颜色。
这是我的代码:
在activity_main.xml中:
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/password_TextInputLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/username_TextInputLayout"
android:layout_alignParentStart="true"
android:layout_alignParentEnd="true"
android:layout_marginStart="32dp"
android:layout_marginTop="32dp"
android:layout_marginEnd="32dp"
android:layout_marginBottom="8dp"
app:counterTextAppearance="@style/CounterStyle"
app:counterOverflowTextAppearance="@style/CharacterOverflow"
app:passwordToggleEnabled="true">
<EditText
android:id="@+id/password_TextField"
style="@style/Widget.AppCompat.AutoCompleteTextView"
android:layout_width="match_parent"
android:layout_height="57dp"
android:background="@color/white"
android:gravity="bottom"
android:hint="@string/password"
android:includeFontPadding="false"
android:inputType="textPassword"
android:paddingStart="4dp"
android:paddingEnd="4dp"
android:paddingBottom="4dp"
android:textSize="18sp" />
</com.google.android.material.textfield.TextInputLayout>
关于themes.xml:
<resources xmlns:tools="http://schemas.android.com/tools">
<!-- Base application theme. -->
<style name="Theme.MateialDesign" parent="Theme.MaterialComponents.DayNight.NoActionBar">
<!-- Primary brand color. -->
<item name="colorPrimary">@color/purple_500</item>
<item name="colorPrimaryVariant">@color/purple_700</item>
<item name="colorOnPrimary">@color/white</item>
<!-- Secondary brand color. -->
<item name="colorSecondary">@color/teal_200</item>
<item name="colorSecondaryVariant">@color/teal_700</item>
<item name="colorOnSecondary">@color/black</item>
<!-- Status bar color. -->
<item name="android:statusBarColor" tools:targetApi="l">?attr/colorPrimaryVariant</item>
<!-- Navigation bar color-->
<item name="android:navigationBarColor">@color/purple_500</item>
<!-- Customize your theme here. -->
<item name="popupTheme">@style/PopupTheme</item>
</style>
<style name="PopupTheme" parent="Theme.AppCompat.Light">
<item name="android:backgroundTint">@color/popup_background</item>
<item name="android:textColor">@color/black</item>
</style>
<style name="CharacterOverflow">
<item name="android:textColor">@color/colorError</item>
</style>
<style name="CounterStyle" parent="TextAppearance.AppCompat.Small">
<item name="android:textColor">@color/colorAcc</item>
</style>
@颜色/紫色500
@颜色/紫色\u 700
@颜色/白色
@颜色/青色200
@颜色/青绿色700
@颜色/黑色
?attr/colorPrimaryVariant
@颜色/紫色500
@风格/流行歌曲
@颜色/背景
@颜色/黑色
@颜色/颜色错误
@颜色/颜色
我测试了来自的所有解决方案,而且我无法为基线设置可绘制图像,因为我想在计数器达到最大值时更改溢出文本的颜色。在测试了许多解决方案后,我不知道该怎么办!我在themes.xml中定义了@color/colorAccent
,但这不起作用