Muh*_*lib 5 android material-design android-textinputlayout material-components material-components-android
这是我应用程序的主要风格
<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>
Run Code Online (Sandbox Code Playgroud)
据我所知,colorControlHighlight 应该为 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>
Run Code Online (Sandbox Code Playgroud)
没有一个 colorControls 应该与新的 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>
Run Code Online (Sandbox Code Playgroud)
只需使用类似的东西:
<com.google.android.material.textfield.TextInputLayout
style="@style/FilledBoxColor"
...>
Run Code Online (Sandbox Code Playgroud)
具有自定义样式:
<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>
Run Code Online (Sandbox Code Playgroud)
默认选择器是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>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1146 次 |
| 最近记录: |