本文介绍了用于TextInputLayout的colorControlActivated不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我应用程序的主要风格
This is my main style for the application
<style name="Theme.RoundRobin" parent="Theme.MaterialComponents.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorSecondaryVariant</item>
<item name="colorAccent">@color/colorPrimaryVariant</item>
<item name="colorControlActivated">@color/colorControlActivated</item>
<item name="colorControlNormal">@color/colorControlNormal</item>
<item name="colorControlHighlight">@color/colorControlNormal</item>
<item name="android:textColorPrimary">@color/textColorPrimary</item>
<item name="android:windowLightStatusBar" tools:targetApi="m">false</item>
</style>
据我所知,colorControlHighlight应该为下划线,标签和文本输入布局中的光标着色.
as far as I know colorControlHighlight should color the underline , the label and the cursor in the textinputlayout.
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/username_til"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="24dp"
android:layout_marginLeft="24dp"
android:layout_marginTop="24dp"
android:layout_marginEnd="24dp"
android:layout_marginRight="24dp"
app:hintTextAppearance="@style/TextAppearance.Subtitle1"
app:layout_constraintBottom_toTopOf="@+id/password_til"
app:layout_constraintEnd_toEndOf="parent"
android:hint="Username"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/usernameEt"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="@style/TextAppearance.Body2"/>
</com.google.android.material.textfield.TextInputLayout>
所有colorControl都不能与新的MaterialCompoents一起使用.
None of the colorControls are supposedly working with the new MaterialCompoents.
我在这里错过了什么吗
我给TextInput设置了这种样式,但是看来MaterialComponents在colorControlsX上无法正常工作
I gave my TextInput this style , yet it appears as if MaterialComponents is not working well with colorControlsX
<style name="Widget.RoundRobin.TextInputLayout.FilledBox" parent="Widget.MaterialComponents.TextInputLayout.FilledBox">
<item name="hintTextAppearance">@style/TextAppearance.Caption</item>
<item name="android:paddingBottom">8dp</item>
<item name="boxBackgroundColor">@color/colorWhite</item>
<item name="android:colorControlHighlight">@color/colorSecondaryVariant</item> // this doesn't work too
</style>
推荐答案
只需使用以下内容:
<com.google.android.material.textfield.TextInputLayout
style="@style/FilledBoxColor"
...>
具有自定义样式:
<style name="FilledBoxColor" parent="Widget.MaterialComponents.TextInputLayout.FilledBox">
<!-- underline color in FilledBox style, border color in OutlinedBox
<item name="boxStrokeColor">@color/text_input_layout_stroke_color</item>
<!-- The color of the label when it is collapsed and the text field is active -->
<item name="hintTextColor">@color/....</item>
<!-- The color of the label in all other text field states (such as resting and disabled) -->
<item name="android:textColorHint">@color/.....</item>
</style>
boxStrokeColor
的默认选择器是:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="?attr/colorPrimary" android:state_focused="true"/>
<!-- 4% overlay over 42% colorOnSurface -->
<item android:alpha="0.46" android:color="?attr/colorOnSurface" android:state_hovered="true"/>
<item android:alpha="0.38" android:color="?attr/colorOnSurface" android:state_enabled="false"/>
<item android:alpha="0.42" android:color="?attr/colorOnSurface"/>
</selector>
这篇关于用于TextInputLayout的colorControlActivated不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!