【问题标题】:I want to set the background color of the entire width of the line in EditText我想在EditText中设置行的整个宽度的背景颜色
【发布时间】:2013-01-08 17:05:34
【问题描述】:

我有一个带有多行文本的 EditText 框。我想将一些线条设置为背景颜色蓝色。我想将 EditText 框的整个宽度设置为蓝色,而不仅仅是文本的背景。

请帮忙!

(我知道我可以通过使用 Span 类将文本的背景设置为蓝色,但希望将蓝色设置为横跨整个线条的宽度 - 即使文本只出现到行的中间)

【问题讨论】:

    标签: android colors textview android-edittext line


    【解决方案1】:

    您可以使用以下 xml 布局自定义您的编辑文本

    以下代码另存为yourWishName.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <selector
    xmlns:android="http://schemas.android.com/apk/res/android">
    
    //You can change the color of the edit text here which removes the border line as well
     <item android:state_focused="true" >
        <shape android:shape="rectangle">
            <gradient
                android:startColor="#FFFFFF"
                android:endColor="#FFFFFF"
                android:angle="270" />
            <stroke
                android:width="3dp"
                android:color="#F8B334" />
            <corners
                android:radius="12dp" /> 
        </shape>
    </item>  
    <item>
        <shape android:shape="rectangle">
            <gradient
                android:startColor="#FFFFFF"
                android:endColor="#FFFFFF"
                android:angle="270" />
            <stroke
                android:width="0dp"
                android:color="#000000" />
            <corners
                android:radius="12dp" /> 
        </shape>
    </item>
    </selector>
    

    在 EditText 中调用 xml android:background="@drawable/yourWishName"

    希望对你有帮助

    【讨论】:

    • 这实际上已经设置了整个edittext框的颜色和形状。我认为这会设置所选线条的颜色。这不是我想要的。我只想将 EditText 框中的 ONE 行的颜色设置为蓝色。 (不是整个编辑文本框背景)。
    • 哦,对不起,我没听懂你的问题
    猜你喜欢
    • 1970-01-01
    • 2017-07-07
    • 2012-01-22
    • 2020-03-20
    • 1970-01-01
    • 1970-01-01
    • 2012-12-27
    • 2012-08-14
    • 2018-05-26
    相关资源
    最近更新 更多