[英]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:
看图片:
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.