有没有办法调试哪个主题正在影响 xml 布局上的给定组件

问题描述 投票:0回答:1

我去过许多 Stack Overflow 页面,寻找在文本输入布局处于活动状态时更改提示颜色的答案。尽管有自定义主题,但默认值会覆盖我的偏好。

我现在想要的只是一种“检查元素”的方法,并准确查看哪些属性正在影响活动提示颜色以及为什么它不是我的强调色。

我的风格:

    <style name="EditTextHint" parent="TextAppearance.AppCompat">
    <item name="android:textColorHint">@color/colorAccent</item>
    <item name="colorControlActivated">@color/colorAccent</item>
    <item name="boxStrokeColor">@color/colorAccent</item>
    <item name="backgroundTint">@color/colorAccent</item>
    </style>

textInputLayout 片段(几乎完全相同:

    <com.google.android.material.textfield.TextInputLayout
    style="@style/EditTextHint"
    android:id="@+id/til1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:padding="8dp">
    <com.google.android.material.textfield.TextInputEditText
    android:id="@+id/name"
    android:layout_width="match_parent"
    android:layout_height="48dp"
    android:hint="@string/name"
    android:imeOptions="actionNext"
    android:singleLine="true" />
    </com.google.android.material.textfield.TextInputLayout>

结果如下:

various text input layouts showing that they are a different colour when activated as opposed to when idle

android xml user-interface layout material-ui
1个回答
0
投票

试试这个,

在 styles.xml 中创建样式

<style name="TextInputStyle" parent="Widget.Design.TextInputLayout">
    <item name="hintTextColor">@color/colorPrimary</item>
    <item name="strokeColor">@color/colorPrimary</item>
    <item name="hintTextAppearance">@style/HintTextAppearance</item>
    <item name="helperTextTextAppearance">@style/HintTextAppearance</item>

</style>

您可以添加提示文本颜色、笔画颜色或您希望 TextInputLayout 看起来像的其他自定义内容。

如果需要,可以使用您的颜色和大小的提示文本样式,在 TextInputStyle 中使用它(或者您可以将此样式直接应用于 TextInputLayout 本身)

<style name="HintTextAppearance">
    <item name="android:textSize">@dimen/caption_size</item>
    <item name="android:color">@color/colorPrimary</item> 
</style>

将此样式 TextInputStyle 应用于您的 TextInputLayout,

如果有效请告诉我

© www.soinside.com 2019 - 2024. All rights reserved.