2014-04-16 174 views

回答

3

试试这个..

<EditText 
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
android:background="@null" 
//Or 
android:background="#00000000" 
//Or 
android:background="@android:color/transparent" 
/> 

编辑

editext.setOnClickListener(new OnClickListener(){ 

     @Override 
     public void onClick(View arg0) { 
      // TODO Auto-generated method stub 
      editext.setBackgroundResource(R.drawable.border); 
     } 

    }); 

或者

editext.setOnTouchListener(new OnTouchListener(){ 

     @Override 
     public boolean onTouch(View v, MotionEvent event) { 
      // TODO Auto-generated method stub 
      editext.setBackgroundResource(R.drawable.border); 
      return true; 
     } 

    }); 
+0

谢谢,当我点击把边框放在一个颜色? – user3383415

+0

@ user3383415对不起,我不明白。你能清楚地告诉我吗? – Hariharan

+0

通过您告诉我的代码,“编辑”文本看起来像我放置的左侧图像。但是当我点击编辑文本来编写不出现的边框时,我希望当我点击编辑文本时,红色边框就像右边的图像一样出现。谢谢 – user3383415

0

试试这个:

定义的EditText象下面这样:在单击在编辑文本集的EditText背景绘制

<EditText 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:background="@null" 
    /> 

,见下文

editext.setOnTouchListener(new OnTouchListener() 
{ 
    @Override 
    public boolean onTouch(View v, MotionEvent event) 
    { 

     editext.setBackground(R.drawable.border); 
     return true; 
    } 

}); 

定义边界绘制如下图所示:

<?xml version="1.0" encoding="UTF-8"?> 
<shape xmlns:android="http://schemas.android.com/apk/res/android"> 
    <solid android:color="@color/white"/>  

    <stroke android:width="1dp" android:color="@color/red"/> 

    <padding android:left="5dp" 
      android:top="5dp" 
      android:right="5dp" 
      android:bottom="5dp" 
      /> 

    <corners android:bottomRightRadius="3dp" android:bottomLeftRadius="3dp" 
    android:topLeftRadius="3dp" android:topRightRadius="3dp"/> 
</shape> 

您可以根据您的要求从可绘制的元素中移除填充和边框元素。