Android 如何更改EditText中底部线条的颜色?
我知道以前有人问过这个问题,但在我的情况下,这个解决方案不起作用。我想更改编辑文本底线颜色,并尝试从其他链接将这一行添加到styles.xml中的主题中Android 如何更改EditText中底部线条的颜色?,android,android-edittext,Android,Android Edittext,我知道以前有人问过这个问题,但在我的情况下,这个解决方案不起作用。我想更改编辑文本底线颜色,并尝试从其他链接将这一行添加到styles.xml中的主题中 <item name="colorControlNormal">#c5c5c5</item> 但不知何故,这在我的情况下是行不通的。我试着改变基本主题,但仍然不适合我。 我想用我的应用程序中的所有EditText来实现这一点,而不仅仅是一个。 还有其他方法吗???在“值”文件夹下编辑Style.xml <styl
<item name="colorControlNormal">#c5c5c5</item>
但不知何故,这在我的情况下是行不通的。我试着改变基本主题,但仍然不适合我。
我想用我的应用程序中的所有EditText来实现这一点,而不仅仅是一个。
还有其他方法吗???在“值”文件夹下编辑Style.xml
<style name="Theme.App.Base" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorControlNormal">#c5c5c5</item>
<item name="colorControlActivated">#c5c5c5</item>
<item name="colorControlHighlight">#c5c5c5</item>
</style>
在drawable文件夹中创建文件edittextborder.xml并写入
?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item><shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<solid android:color="#ffffff" />
</shape></item>
</selector>
在编辑文本中。我更喜欢使用9个补丁图像来编辑文本自定义颜色。 这是一个很棒的在线工具生成器,适用于所有小部件
为每个dpi文件夹生成和下载。并使用背景应用它。解决方案如下- 我想让你去看看。 提供主题名称并选择所需的颜色。 选择要更改颜色的组件。在你的情况下,它的编辑文本。 最后点击下载Zip。 拔出拉链并在项目中使用。 试试这个 .xml文件
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:padding="5dp">
<EditText
android:id="@+id/text_to"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/customborder" //.xml file for edittext
android:clickable="true"
android:padding="5dip"
android:text="Text_to"
android:textColor="@color/black"
android:textSize="@dimen/font_normal_size" />
</LinearLayout>
customborder.xml
使用Rohit的答案和此链接提供的黑客攻击。我能够实现我想要的行为。下面是可绘制文件夹文件的代码
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle" >
<solid android:color="@android:color/transparent" />
</shape>
</item>
<item android:top="-2dp" android:right="-2dp" android:left="-2dp">
<shape>
<solid android:color="@android:color/transparent" />
<stroke
android:width="1dp"
android:color="#FFFFFF" />
</shape>
</item>
</layer-list>
可以使用以下方法在xml中对此进行更改:
android:backgroundTint="@color/blue"
你在使用appcompact活动吗?检查Rohit Heera的回答,张贴你的布局和样式文件,我写的代码不起作用。你为什么不仔细阅读这个问题?你不能添加colorControlActivated和colorControlHighlight?我不想要它们,所以我没有添加它们。我可以更改激活的颜色,但不知何故正常不起作用。我不想在选择编辑文本时使用它。我希望它默认为白色是的,它默认为您的edittext它不在选择状态OK让我试试,然后我会告诉您,只要尝试一次,它肯定会解决您的问题这是用Shapetin中提供的颜色填充整个edittext需要最低android版本21当它不聚焦时,您希望底线颜色相同吗?问题现在解决了但正如你所问。活动打开时,所有EditText底线颜色均为黑色,聚焦时变为白色。白色部分是理想的行为,但我想在不聚焦时更改颜色您的问题解决了吗?@Vivek Mishrano这也创造了所有方面的完整边界
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle" >
<solid android:color="@android:color/transparent" />
</shape>
</item>
<item android:top="-2dp" android:right="-2dp" android:left="-2dp">
<shape>
<solid android:color="@android:color/transparent" />
<stroke
android:width="1dp"
android:color="#FFFFFF" />
</shape>
</item>
</layer-list>
android:backgroundTint="@color/blue"