问题
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>
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>
None of the colorControls are supposedly working with the new MaterialCompoents.
Am i missing something here
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>
回答1:
Just use something like:
<com.google.android.material.textfield.TextInputLayout
style="@style/FilledBoxColor"
...>
with a custom style:
<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>
The default selector for the boxStrokeColor
is:
<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>
来源:https://stackoverflow.com/questions/56742148/colorcontrolactivated-for-textinputlayout-doesnt-work