简体   繁体   English

如何使用 LinearLayout 更改编辑文本背景颜色?

[英]How to change edit text background color with LinearLayout?

I want to change the LinearLayout background color and I want to reflect the changes to the editText, but the problem is I will get two different colors.我想改变LinearLayout背景颜色,我想把改变反映到editText,但问题是我会得到两个不同的colors。 I know how to to change the background of editText, but I want to change the LinearLayout and the editText background color changes with it.我知道如何更改 editText 的背景,但我想更改 LinearLayout 并且 editText 背景颜色随之更改。 When I change the layout background, the editText always gets a lighter color which is not what I want.当我更改布局背景时,editText 总是得到较浅的颜色,这不是我想要的。 Look at the image:看图片:

editText 显示较浅的黄色背景颜色,包含的 LinearLayout

The background of delete button and checkbox changes with the layout background but not the editText.删除按钮和复选框的背景会随布局背景而变化,但不会随 editText 变化。 As I said I don't want to set the background of editText on its own.正如我所说,我不想自己设置editText的背景。 May be there is a way to do with styles but it's not clear for me.可能有办法处理 styles 但我不清楚。

First: make new xml file in res/drawable name it rounded_edit_text then paste this:首先:在 res/drawable 名称中创建新的 xml 文件,将其命名为 rounded_edit_text 然后粘贴:

    <?xml version="1.0" encoding="utf-8"?>
        <shape  xmlns:android="http://schemas.android.com/apk/res/android" 
            android:shape="rectangle" android:padding="10dp">
            <solid android:color="#F9966B" />
            <corners
                android:bottomRightRadius="15dp"
                android:bottomLeftRadius="15dp"
                android:topLeftRadius="15dp"
                android:topRightRadius="15dp" />
        </shape>

// Second: in res/layout copy and past following code (code of EditText) //第二:在 res/layout 复制和过去的以下代码(EditText 的代码)

<EditText
    android:id="@+id/txtdoctor"
    android:layout_width="match_parent"
    android:layout_height="30dp"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true"
    android:background="@drawable/rounded_edit_text"
    android:ems="10" >
    <requestFocus />
</EditText>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何多次更改LinearLayout View背景色? - How to change LinearLayout View background color numerous times? 如何更改微调器项目中文本的背景颜色? - How to change the background color of a text in a spinner item? 按下按钮时如何更改按钮文本颜色和背景颜色 - How to change button text color and background color while button is pressed 如何在ActionBar上更改标题文本的颜色和背景的颜色? - How to change the title text color and the color of the background on the ActionBar? 以编程方式更改 LinearLayout 的背景颜色 - Changing programmatically the background color of LinearLayout LinearLayout带有圆角和背景颜色 - LinearLayout with rounded corners and background color 如何以编程方式在 android 中使用图像作为线性布局的背景色 - How to use image for background color of linearlayout in android programmatically 如何在不使用XML的情况下更改ListView背景和文本颜色 - How to change ListView background and text color without XML 使用昼夜主题时如何更改布局的背景/文本颜色 - How to change the background/text color of a layout when daynight theme is used 如何在Java中更改实际JButton的颜色? 不是背景,不是文字 - How do I change the color of an actual JButton in Java? Not the background and not the text
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM