Nar*_*uto 28 android android-layout android-edittext
如果我EditText使用下面的代码更改我的背景颜色,它看起来像是缩小的框,并且它不保持默认存在的蓝色底部边框的ICS主题EditText.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#99000000"
>
<EditText
android:id="@+id/id_nick_name"
android:layout_marginTop="80dip"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#ffffff"
/>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dip"
android:layout_marginLeft="20dip"
android:layout_marginRight="20dip"
android:orientation="horizontal"
android:layout_below="@+id/id_nick_name">
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="add"
android:layout_weight="1"
/>
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="cancel"
android:layout_weight="1"
/>
</LinearLayout>
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
这是它的样子:

Bar*_*zky 39
一行惰性代码:
mEditText.getBackground().setColorFilter(Color.RED, PorterDuff.Mode.SRC_ATOP);
Run Code Online (Sandbox Code Playgroud)
小智 19
这是最好的方法
首先:xml在res/中drawable命名新文件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>
Run Code Online (Sandbox Code Playgroud)
第二:在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>
Run Code Online (Sandbox Code Playgroud)
RN3*_*ick 11
我创建了color.xml文件,用于命名我的颜色名称(黑色,白色......)
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="white">#ffffff</color>
<color name="black">#000000</color>
</resources>
Run Code Online (Sandbox Code Playgroud)
在EditText中,设置颜色
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="asdsadasdasd"
android:textColor="@color/black"
android:background="@color/white"
/>
Run Code Online (Sandbox Code Playgroud)
或者在style.xml中使用样式:
<style name="EditTextStyleWhite" parent="android:style/Widget.EditText">
<item name="android:textColor">@color/black</item>
<item name="android:background">@color/white</item>
</style>
Run Code Online (Sandbox Code Playgroud)
并将ctreated样式添加到EditText:
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="asdsadasdasd"
style="@style/EditTextStyleWhite"
/>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
113287 次 |
| 最近记录: |