Android:在改变EditText背景颜色时,EditText样式发生了变化

嗨当我更改两个EditText的EditText的背景颜色时,它们看起来像两个合并.

我的布局代码就像这样`

<EditText
    android:id="@+id/editText4"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:ems="10"
    android:hint="Text1"
    android:singleLine="true" />

<EditText
    android:id="@+id/editText1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:ems="10"
    android:hint="Text2"
    android:singleLine="true" >
</EditText>

<AutoCompleteTextView android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:singleLine="true"
    android:imeOptions="actionNext"/>

<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" >

    <EditText
        android:id="@+id/editText2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:ems="10"
        android:hint="Text3"
        android:singleLine="true" />

</LinearLayout>
 <LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" >

    <EditText
        android:id="@+id/editText2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:ems="10"
        android:hint="Text4"
        android:singleLine="true" />

</LinearLayout>

 <Button
     android:id="@+id/button1"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:text="Button" />

`

和我的活动代码是这样的

public class MainActivity extends Activity {

EditText editText1,editText2,editText3,editText4;
Button button;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    init();

    button.setonClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            editText1.setBackgroundColor(getResources().getColor(android.R.color.primary_text_dark_nodisable));
            editText3.setBackgroundColor(getResources().getColor(android.R.color.darker_gray));

        }
    });

}

private void init() {
    editText1 = (EditText) findViewById(R.id.editText1);
    editText2 = (EditText) findViewById(R.id.editText2);
    editText3 = (EditText) findViewById(R.id.editText4);
    button = (Button) findViewById(R.id.button1);

}

}

请参阅下面的屏幕截图

单击按钮之前的布局

单击按钮后的布局

解决方法

正如你可以看到 here使用EditText.setBackgroundColor(任何颜色)也会为你的轮廓着色.为了保持大纲方面,我建议将edittext包含在表格行中并使用边距.在xml中尝试这个并查看结果:

<TableRow
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@android:color/black"
    android:orientation="vertical" >

    <EditText
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@android:color/holo_orange_dark"
        android:layout_margin="1dip"
        android:text="cosmincalistru" />
</TableRow>

相关文章

Android性能优化——之控件的优化 前面讲了图像的优化,接下...
前言 上一篇已经讲了如何实现textView中粗字体效果,里面主要...
最近项目重构,涉及到了数据库和文件下载,发现GreenDao这个...
WebView加载页面的两种方式 一、加载网络页面 加载网络页面,...
给APP全局设置字体主要分为两个方面来介绍 一、给原生界面设...
前言 最近UI大牛出了一版新的效果图,按照IOS的效果做的,页...