首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >用于TextInputLayout的colorControlActivated不起作用

用于TextInputLayout的colorControlActivated不起作用
EN

Stack Overflow用户
提问于 2019-06-25 02:37:09
回答 1查看 1.3K关注 0票数 5

这是我的应用程序的主要样式

代码语言:javascript
运行
复制
<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应该对文本输入布局中的下划线、标签和光标进行着色。

代码语言:javascript
运行
复制
<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>

据推测,没有一个colorControls可以与新的MaterialCompoents一起工作。

我是不是漏掉了什么

我给我的TextInput提供了这种风格,但是看起来MaterialComponents似乎不能很好地与colorControlsX一起工作

代码语言:javascript
运行
复制
<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>
EN

回答 1

Stack Overflow用户

发布于 2019-09-11 05:57:38

只需使用类似以下内容:

代码语言:javascript
运行
复制
    <com.google.android.material.textfield.TextInputLayout
        style="@style/FilledBoxColor"
        ...>

使用自定义样式:

代码语言:javascript
运行
复制
  <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的默认选择器为:

代码语言:javascript
运行
复制
<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>

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56742148

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档