这是我应用程序的主要风格
<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应该为下划线,标签和文本输入布局中的光标着色。
<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一起使用。
我在这里想念什么吗
我给TextInput设置了这种样式,但似乎MaterialComponents在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>
答案 0 :(得分:0)
只需使用以下内容:
<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>