android - 问题:更改 android 中未聚焦的 TextInputLayout 的边框颜色或框笔划
问题描述
我有一个非常具体的问题,即在 TextInputLayout 未聚焦时更改其文本框的轮廓。我似乎找不到一个属性来更改我的“未聚焦”文本框的边框颜色。
这是我正在尝试做的一个视觉示例:
this (textbox):border 的颜色不是白色。目前它没有重点。单击它后,它变成白色:
我不知道我需要更改什么,似乎没有属性可以更改它。
我也在使用材料设计文本输入布局样式,虽然我不知道这是否会影响它。
这是我的文本框的 xml 代码:
<other layouts ... >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="70dp"
android:layout_gravity="bottom"
android:layout_margin="5dp"
android:background="@drawable/item_recycler_view">
<android.support.design.widget.TextInputLayout
android:id="@+id/dialog_text_input_layout"
style="@style/Widget.AppTheme.TextInputLayoutList"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Quick Add..."
android:textColorHint="@color/colorWhite"
app:boxStrokeColor="@color/colorWhite"
app:errorEnabled="true"
>
<android.support.design.widget.TextInputEditText
android:id="@+id/dialog_edit_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="text"
android:maxLines="1"
android:textColor="@color/colorWhite"
android:textSize="14sp" />
</android.support.design.widget.TextInputLayout>
</RelativeLayout>
</other layouts...>
以下是我为此使用的样式:
<style name="TextAppearance.AppTheme.TextInputLayout.HintTextAlt" parent="TextAppearance.MaterialComponents.Subtitle2">
<item name="android:textColor">@color/colorWhite</item>
</style>
<style name="Widget.AppTheme.TextInputLayoutList" parent="Widget.MaterialComponents.TextInputLayout.OutlinedBox">
<item name="hintTextAppearance">@style/TextAppearance.AppTheme.TextInputLayout.HintTextAlt</item>
<item name="boxStrokeColor">@color/colorWhite</item>
<item name="boxCornerRadiusBottomEnd">5dp</item>
<item name="boxCornerRadiusBottomStart">5dp</item>
<item name="boxCornerRadiusTopEnd">5dp</item>
<item name="boxCornerRadiusTopStart">5dp</item>
<item name="android:layout_margin">5dp</item>
</style>
谢谢,欢迎任何帮助或建议!
解决方案
如果要在未聚焦模式下设置轮廓框的颜色而不是默认的黑色,则必须在colors.xml
文件中添加此行,这将覆盖轮廓框的默认颜色。
照原样复制这一行。你可以改变你想要的颜色。
<color name="mtrl_textinput_default_box_stroke_color">#fff</color>
直到现在它都可以工作,为了对 TextInputLayout 进行更多控制,您可以在 styles.xml 中添加此样式
<style name="TextInputLayoutStyle" parent="Widget.MaterialComponents.TextInputLayout.OutlinedBox.Dense">
<item name="boxStrokeColor">#fff</item>
<item name="boxStrokeWidth">2dp</item>
</style>
然后将主题添加到 TextInputLayout
android:theme="@style/TextInputLayoutStyle"
推荐阅读
- python - 如何使用 tweepy 3.10.0 回复计数和报价计数?
- vue.js - 为打字稿文件构建后链 vue-cli webpack
- file - 用于从 Google Drive 重命名和下载文件的 Google 电子表格脚本
- r - 将数据框每一行中的每个元素除以 R 中的一行中的值
- unreal-engine4 - 虚幻中的样条生成
- python - 为什么我不能配置我的 Pip3 安装
- spring-boot - 重新平衡时的Kafka消费者
- python - 无法在 sympy 中整合简单的正态分布,取决于均值和偏差常数
- javascript - 使用有状态偏移量获取数组的块
- java - 如何调用作为字符串值给出的调用?