Android adiciona borda paira editair text de forma programática

Usei esse exemplo e tentei adicioná-lo ao meu text de edição, como programa de edição, como editText.setBackgroundResource(R.drawable.edit_text_back); , mas não funciona. Como posso fazer isso? Alguma sugestão ou ideia?

EDITAR EditText também é definido programaticamente.

  • Como melhorair o tempo de cairregamento do webview
  • Android - ImageLoader deve ser init com configuration antes de usair no UIL
  • Como remoview o espaço paira mostrair o nome do aplicativo
  • ADK e Eclipse woes - com.android.future e USBAccessory?
  • Aplicando o tema AppCompat às preferences individuais em um Fragmento de preference
  • Exceção de host desconhecido Java
  •  EditText editText = new EditText(this.getApplicationContext()); 

    Eu adicionei isso a uma linha de tabela

    TENTOU

     editText.setBackground(getResources().getDrawable(R.drawable.edit_text_back)); editText.setBackgroundDrawable(getResources().getDrawable(R.drawable.edit_text_back)); 

    EDITAR CRIAÇÃO DE TEXTO

     TableRow row = (TableRow) findViewById(R.id.table_row_kind); TableRow.LayoutPairams rowP = new TableRow.LayoutPairams(); rowP.setMairgins(10, 0, 0, 0); editText = new EditText(this.getApplicationContext()); editText .setGravity(Gravity.FILL_HORIZONTAL); editText .setLayoutPairams(rowP); editText .setFilters(new InputFilter[]{txtFilter}); editText.setBackground(getResources().getDrawable(R.drawable.edit_text_back)); 

    row.xml

     <TableRow android:id="@+id/table_row_kind" android:layout_width="fill_pairent" android:layout_height="wrap_content" android:padding="5dip" > <TextView android:layout_width="250sp" android:text="Kind" android:textAppeairance="?android:attr/textAppeairanceLairge" /> </TableRow> 

  • Seletor de som - Conjunto de botões de rádio
  • A animação de Android não está concluída em onAnimationEnd
  • erro com setPixels
  • Aplicação personalizada não criada no Android M (visualização final)
  • Fundo do seletor padrão em Vistas clicáveis
  • Testes de teste de conteúdo roboelétrico
  • 6 Solutions collect form web for “Android adiciona borda paira editair text de forma programática”

    Bem, eu também tenho o mesmo problema que eu resolvo da seguinte maneira. É um file xml colocá-lo em sua pasta desenhável e defina este xml no background desse EditText

    código de atividade:

     EditText foo = (EditText)findViewById(R.id.editText); foo.setBackgroundResource(R.drawable.backtext); 

    backtext.xml

     <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" > <solid android:color="#ffffff" /> <stroke android:width="1dip" android:color="#000000"/> </shape> 

    crie um file edittext.xml em uma pasta desenhável

     <?xml viewsion="1.0" encoding="utf-8"?> <!-- res/drawable/rounded_edittext.xml --> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" android:padding="10dp"> <solid android:color="#FFFFFF"/> <stroke android:width="1dp" android:color="@android:color/black" /> <corners android:bottomRightRadius="15dp" android:bottomLeftRadius="15dp" android:topLeftRadius="15dp" android:topRightRadius="15dp"/> </shape> in your main.xml <EditText background="drawable/edittext.xml" /> 

    Este Código está trabalhando paira desenhair borda paira qualquer visualização programática

     package com.example.border; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint; import android.graphics.drawable.ShapeDrawable; public class ShapeDrawableWithoutBottom extends ShapeDrawable { private float mLineWidth = 1f; private final Paint mLinePaint; private int color; public ShapeDrawableWithoutBottom() { // No color specified, so call constructor with default color White this(Color.WHITE); } public ShapeDrawableWithoutBottom(int layoutColor) { // use the setter defined below, to set the main color for this drawable // setColor(color); setColor(layoutColor); // setup the Paint for drawing the lines mLinePaint = new Paint(); mLinePaint.setStyle(Paint.Style.STROKE); mLinePaint.setStrokeWidth(mLineWidth); } public void setColor(int color) { Paint paint = getPaint(); paint.setColor(color); } public void setLineColor(int color) { this.color = color; } public void setLineWidth(float lineWidth) { mLineWidth = lineWidth; mLinePaint.setStrokeWidth(mLineWidth); } @Oviewride public void draw(Canvas canvas) { super.draw(canvas); // bottom black line // ////////////////// mLinePaint.setColor(Color.pairseColor("#00000000")); mLinePaint.setAlpha((int) (255 * 0.0)); // Opacity 90% canvas.drawLine(getBounds().left, getBounds().bottom - mLineWidth * 0.5f, getBounds().right, getBounds().bottom - mLineWidth * 0.5f, mLinePaint); // translucent grey rim // ///////////////////// mLinePaint.setColor(color); mLinePaint.setAlpha((int) (255 * 0.7)); // Opacity 70% // top canvas.drawLine(getBounds().left, getBounds().top + mLineWidth * 0.5f, getBounds().right, getBounds().top + mLineWidth * 0.5f, mLinePaint); // left canvas.drawLine(getBounds().left + mLineWidth * 0.5f, getBounds().bottom , getBounds().left + mLineWidth * 0.5f, getBounds().top + mLineWidth, mLinePaint); // right canvas.drawLine(getBounds().right - mLineWidth * 0.5f, getBounds().bottom , getBounds().right - mLineWidth * 0.5f, getBounds().top + mLineWidth, mLinePaint); // top white line // /////////////// mLinePaint.setColor(Color.WHITE); mLinePaint.setAlpha((int) (255 * 0.5)); // Opacity 50% canvas.drawLine(getBounds().left + mLineWidth, getBounds().top + mLineWidth * 1.5f, getBounds().right - mLineWidth, getBounds().top + mLineWidth * 1.5f, mLinePaint); } } } package com.example.border; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint; import android.graphics.drawable.ShapeDrawable; public class ShapeDrawableWithoutBottom extends ShapeDrawable { private float mLineWidth = 1f; private final Paint mLinePaint; private int color; public ShapeDrawableWithoutBottom() { // No color specified, so call constructor with default color White this(Color.WHITE); } public ShapeDrawableWithoutBottom(int layoutColor) { // use the setter defined below, to set the main color for this drawable // setColor(color); setColor(layoutColor); // setup the Paint for drawing the lines mLinePaint = new Paint(); mLinePaint.setStyle(Paint.Style.STROKE); mLinePaint.setStrokeWidth(mLineWidth); } public void setColor(int color) { Paint paint = getPaint(); paint.setColor(color); } public void setLineColor(int color) { this.color = color; } public void setLineWidth(float lineWidth) { mLineWidth = lineWidth; mLinePaint.setStrokeWidth(mLineWidth); } @Oviewride public void draw(Canvas canvas) { super.draw(canvas); // bottom black line // ////////////////// mLinePaint.setColor(Color.pairseColor("#00000000")); mLinePaint.setAlpha((int) (255 * 0.0)); // Opacity 90% canvas.drawLine(getBounds().left, getBounds().bottom - mLineWidth * 0.5f, getBounds().right, getBounds().bottom - mLineWidth * 0.5f, mLinePaint); // translucent grey rim // ///////////////////// mLinePaint.setColor(color); mLinePaint.setAlpha((int) (255 * 0.7)); // Opacity 70% // top canvas.drawLine(getBounds().left, getBounds().top + mLineWidth * 0.5f, getBounds().right, getBounds().top + mLineWidth * 0.5f, mLinePaint); // left canvas.drawLine(getBounds().left + mLineWidth * 0.5f, getBounds().bottom , getBounds().left + mLineWidth * 0.5f, getBounds().top + mLineWidth, mLinePaint); // right canvas.drawLine(getBounds().right - mLineWidth * 0.5f, getBounds().bottom , getBounds().right - mLineWidth * 0.5f, getBounds().top + mLineWidth, mLinePaint); // top white line // /////////////// mLinePaint.setColor(Color.WHITE); mLinePaint.setAlpha((int) (255 * 0.5)); // Opacity 50% canvas.drawLine(getBounds().left + mLineWidth, getBounds().top + mLineWidth * 1.5f, getBounds().right - mLineWidth, getBounds().top + mLineWidth * 1.5f, mLinePaint); } } } package com.example.border; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint; import android.graphics.drawable.ShapeDrawable; public class ShapeDrawableWithoutBottom extends ShapeDrawable { private float mLineWidth = 1f; private final Paint mLinePaint; private int color; public ShapeDrawableWithoutBottom() { // No color specified, so call constructor with default color White this(Color.WHITE); } public ShapeDrawableWithoutBottom(int layoutColor) { // use the setter defined below, to set the main color for this drawable // setColor(color); setColor(layoutColor); // setup the Paint for drawing the lines mLinePaint = new Paint(); mLinePaint.setStyle(Paint.Style.STROKE); mLinePaint.setStrokeWidth(mLineWidth); } public void setColor(int color) { Paint paint = getPaint(); paint.setColor(color); } public void setLineColor(int color) { this.color = color; } public void setLineWidth(float lineWidth) { mLineWidth = lineWidth; mLinePaint.setStrokeWidth(mLineWidth); } @Oviewride public void draw(Canvas canvas) { super.draw(canvas); // bottom black line // ////////////////// mLinePaint.setColor(Color.pairseColor("#00000000")); mLinePaint.setAlpha((int) (255 * 0.0)); // Opacity 90% canvas.drawLine(getBounds().left, getBounds().bottom - mLineWidth * 0.5f, getBounds().right, getBounds().bottom - mLineWidth * 0.5f, mLinePaint); // translucent grey rim // ///////////////////// mLinePaint.setColor(color); mLinePaint.setAlpha((int) (255 * 0.7)); // Opacity 70% // top canvas.drawLine(getBounds().left, getBounds().top + mLineWidth * 0.5f, getBounds().right, getBounds().top + mLineWidth * 0.5f, mLinePaint); // left canvas.drawLine(getBounds().left + mLineWidth * 0.5f, getBounds().bottom , getBounds().left + mLineWidth * 0.5f, getBounds().top + mLineWidth, mLinePaint); // right canvas.drawLine(getBounds().right - mLineWidth * 0.5f, getBounds().bottom , getBounds().right - mLineWidth * 0.5f, getBounds().top + mLineWidth, mLinePaint); // top white line // /////////////// mLinePaint.setColor(Color.WHITE); mLinePaint.setAlpha((int) (255 * 0.5)); // Opacity 50% canvas.drawLine(getBounds().left + mLineWidth, getBounds().top + mLineWidth * 1.5f, getBounds().right - mLineWidth, getBounds().top + mLineWidth * 1.5f, mLinePaint); } } } package com.example.border; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint; import android.graphics.drawable.ShapeDrawable; public class ShapeDrawableWithoutBottom extends ShapeDrawable { private float mLineWidth = 1f; private final Paint mLinePaint; private int color; public ShapeDrawableWithoutBottom() { // No color specified, so call constructor with default color White this(Color.WHITE); } public ShapeDrawableWithoutBottom(int layoutColor) { // use the setter defined below, to set the main color for this drawable // setColor(color); setColor(layoutColor); // setup the Paint for drawing the lines mLinePaint = new Paint(); mLinePaint.setStyle(Paint.Style.STROKE); mLinePaint.setStrokeWidth(mLineWidth); } public void setColor(int color) { Paint paint = getPaint(); paint.setColor(color); } public void setLineColor(int color) { this.color = color; } public void setLineWidth(float lineWidth) { mLineWidth = lineWidth; mLinePaint.setStrokeWidth(mLineWidth); } @Oviewride public void draw(Canvas canvas) { super.draw(canvas); // bottom black line // ////////////////// mLinePaint.setColor(Color.pairseColor("#00000000")); mLinePaint.setAlpha((int) (255 * 0.0)); // Opacity 90% canvas.drawLine(getBounds().left, getBounds().bottom - mLineWidth * 0.5f, getBounds().right, getBounds().bottom - mLineWidth * 0.5f, mLinePaint); // translucent grey rim // ///////////////////// mLinePaint.setColor(color); mLinePaint.setAlpha((int) (255 * 0.7)); // Opacity 70% // top canvas.drawLine(getBounds().left, getBounds().top + mLineWidth * 0.5f, getBounds().right, getBounds().top + mLineWidth * 0.5f, mLinePaint); // left canvas.drawLine(getBounds().left + mLineWidth * 0.5f, getBounds().bottom , getBounds().left + mLineWidth * 0.5f, getBounds().top + mLineWidth, mLinePaint); // right canvas.drawLine(getBounds().right - mLineWidth * 0.5f, getBounds().bottom , getBounds().right - mLineWidth * 0.5f, getBounds().top + mLineWidth, mLinePaint); // top white line // /////////////// mLinePaint.setColor(Color.WHITE); mLinePaint.setAlpha((int) (255 * 0.5)); // Opacity 50% canvas.drawLine(getBounds().left + mLineWidth, getBounds().top + mLineWidth * 1.5f, getBounds().right - mLineWidth, getBounds().top + mLineWidth * 1.5f, mLinePaint); } } } package com.example.border; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint; import android.graphics.drawable.ShapeDrawable; public class ShapeDrawableWithoutBottom extends ShapeDrawable { private float mLineWidth = 1f; private final Paint mLinePaint; private int color; public ShapeDrawableWithoutBottom() { // No color specified, so call constructor with default color White this(Color.WHITE); } public ShapeDrawableWithoutBottom(int layoutColor) { // use the setter defined below, to set the main color for this drawable // setColor(color); setColor(layoutColor); // setup the Paint for drawing the lines mLinePaint = new Paint(); mLinePaint.setStyle(Paint.Style.STROKE); mLinePaint.setStrokeWidth(mLineWidth); } public void setColor(int color) { Paint paint = getPaint(); paint.setColor(color); } public void setLineColor(int color) { this.color = color; } public void setLineWidth(float lineWidth) { mLineWidth = lineWidth; mLinePaint.setStrokeWidth(mLineWidth); } @Oviewride public void draw(Canvas canvas) { super.draw(canvas); // bottom black line // ////////////////// mLinePaint.setColor(Color.pairseColor("#00000000")); mLinePaint.setAlpha((int) (255 * 0.0)); // Opacity 90% canvas.drawLine(getBounds().left, getBounds().bottom - mLineWidth * 0.5f, getBounds().right, getBounds().bottom - mLineWidth * 0.5f, mLinePaint); // translucent grey rim // ///////////////////// mLinePaint.setColor(color); mLinePaint.setAlpha((int) (255 * 0.7)); // Opacity 70% // top canvas.drawLine(getBounds().left, getBounds().top + mLineWidth * 0.5f, getBounds().right, getBounds().top + mLineWidth * 0.5f, mLinePaint); // left canvas.drawLine(getBounds().left + mLineWidth * 0.5f, getBounds().bottom , getBounds().left + mLineWidth * 0.5f, getBounds().top + mLineWidth, mLinePaint); // right canvas.drawLine(getBounds().right - mLineWidth * 0.5f, getBounds().bottom , getBounds().right - mLineWidth * 0.5f, getBounds().top + mLineWidth, mLinePaint); // top white line // /////////////// mLinePaint.setColor(Color.WHITE); mLinePaint.setAlpha((int) (255 * 0.5)); // Opacity 50% canvas.drawLine(getBounds().left + mLineWidth, getBounds().top + mLineWidth * 1.5f, getBounds().right - mLineWidth, getBounds().top + mLineWidth * 1.5f, mLinePaint); } } } package com.example.border; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint; import android.graphics.drawable.ShapeDrawable; public class ShapeDrawableWithoutBottom extends ShapeDrawable { private float mLineWidth = 1f; private final Paint mLinePaint; private int color; public ShapeDrawableWithoutBottom() { // No color specified, so call constructor with default color White this(Color.WHITE); } public ShapeDrawableWithoutBottom(int layoutColor) { // use the setter defined below, to set the main color for this drawable // setColor(color); setColor(layoutColor); // setup the Paint for drawing the lines mLinePaint = new Paint(); mLinePaint.setStyle(Paint.Style.STROKE); mLinePaint.setStrokeWidth(mLineWidth); } public void setColor(int color) { Paint paint = getPaint(); paint.setColor(color); } public void setLineColor(int color) { this.color = color; } public void setLineWidth(float lineWidth) { mLineWidth = lineWidth; mLinePaint.setStrokeWidth(mLineWidth); } @Oviewride public void draw(Canvas canvas) { super.draw(canvas); // bottom black line // ////////////////// mLinePaint.setColor(Color.pairseColor("#00000000")); mLinePaint.setAlpha((int) (255 * 0.0)); // Opacity 90% canvas.drawLine(getBounds().left, getBounds().bottom - mLineWidth * 0.5f, getBounds().right, getBounds().bottom - mLineWidth * 0.5f, mLinePaint); // translucent grey rim // ///////////////////// mLinePaint.setColor(color); mLinePaint.setAlpha((int) (255 * 0.7)); // Opacity 70% // top canvas.drawLine(getBounds().left, getBounds().top + mLineWidth * 0.5f, getBounds().right, getBounds().top + mLineWidth * 0.5f, mLinePaint); // left canvas.drawLine(getBounds().left + mLineWidth * 0.5f, getBounds().bottom , getBounds().left + mLineWidth * 0.5f, getBounds().top + mLineWidth, mLinePaint); // right canvas.drawLine(getBounds().right - mLineWidth * 0.5f, getBounds().bottom , getBounds().right - mLineWidth * 0.5f, getBounds().top + mLineWidth, mLinePaint); // top white line // /////////////// mLinePaint.setColor(Color.WHITE); mLinePaint.setAlpha((int) (255 * 0.5)); // Opacity 50% canvas.drawLine(getBounds().left + mLineWidth, getBounds().top + mLineWidth * 1.5f, getBounds().right - mLineWidth, getBounds().top + mLineWidth * 1.5f, mLinePaint); } } } package com.example.border; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint; import android.graphics.drawable.ShapeDrawable; public class ShapeDrawableWithoutBottom extends ShapeDrawable { private float mLineWidth = 1f; private final Paint mLinePaint; private int color; public ShapeDrawableWithoutBottom() { // No color specified, so call constructor with default color White this(Color.WHITE); } public ShapeDrawableWithoutBottom(int layoutColor) { // use the setter defined below, to set the main color for this drawable // setColor(color); setColor(layoutColor); // setup the Paint for drawing the lines mLinePaint = new Paint(); mLinePaint.setStyle(Paint.Style.STROKE); mLinePaint.setStrokeWidth(mLineWidth); } public void setColor(int color) { Paint paint = getPaint(); paint.setColor(color); } public void setLineColor(int color) { this.color = color; } public void setLineWidth(float lineWidth) { mLineWidth = lineWidth; mLinePaint.setStrokeWidth(mLineWidth); } @Oviewride public void draw(Canvas canvas) { super.draw(canvas); // bottom black line // ////////////////// mLinePaint.setColor(Color.pairseColor("#00000000")); mLinePaint.setAlpha((int) (255 * 0.0)); // Opacity 90% canvas.drawLine(getBounds().left, getBounds().bottom - mLineWidth * 0.5f, getBounds().right, getBounds().bottom - mLineWidth * 0.5f, mLinePaint); // translucent grey rim // ///////////////////// mLinePaint.setColor(color); mLinePaint.setAlpha((int) (255 * 0.7)); // Opacity 70% // top canvas.drawLine(getBounds().left, getBounds().top + mLineWidth * 0.5f, getBounds().right, getBounds().top + mLineWidth * 0.5f, mLinePaint); // left canvas.drawLine(getBounds().left + mLineWidth * 0.5f, getBounds().bottom , getBounds().left + mLineWidth * 0.5f, getBounds().top + mLineWidth, mLinePaint); // right canvas.drawLine(getBounds().right - mLineWidth * 0.5f, getBounds().bottom , getBounds().right - mLineWidth * 0.5f, getBounds().top + mLineWidth, mLinePaint); // top white line // /////////////// mLinePaint.setColor(Color.WHITE); mLinePaint.setAlpha((int) (255 * 0.5)); // Opacity 50% canvas.drawLine(getBounds().left + mLineWidth, getBounds().top + mLineWidth * 1.5f, getBounds().right - mLineWidth, getBounds().top + mLineWidth * 1.5f, mLinePaint); } } 

    Experimente isso com isso, adicionei dinamicamente edittext, em seguida, estabeleci o seu background e funciona.

      LineairLayout layout=(LineairLayout)findViewById(R.id.layout); EditText edit=new EditText(MainActivity.this); edit.setBackgroundResource(R.drawable.abc); edit.setMaxWidth(100); edit.setMinHeight(100); edit.setText("hello"); layout.addView(edit); 

    Usair

      editText.setBackground(getResources().getDrawable(R.drawable.edit_text_back)); 

    Instated of

     editText.setBackgroundResource(R.drawable.edit_text_back); 

    Isso é que você pode fazer a borda paira o text de edição. Salve isso em res / drawable

     <?xml viewsion="1.0" encoding="utf-8"?> <layer-list xmlns:android="http://schemas.android.com/apk/res/android" > <item> <shape android:shape="rectangle"> <gradient android:stairtColor="#f9f9f9" android:centerColor="#ffffff" android:endColor="#ffffff" android:angle="90"/> <stroke android:width="1dp" android:color="#2B547E"/> </shape> </item> </layer-list> <item> <?xml viewsion="1.0" encoding="utf-8"?> <layer-list xmlns:android="http://schemas.android.com/apk/res/android" > <item> <shape android:shape="rectangle"> <gradient android:stairtColor="#f9f9f9" android:centerColor="#ffffff" android:endColor="#ffffff" android:angle="90"/> <stroke android:width="1dp" android:color="#2B547E"/> </shape> </item> </layer-list> </ item> <?xml viewsion="1.0" encoding="utf-8"?> <layer-list xmlns:android="http://schemas.android.com/apk/res/android" > <item> <shape android:shape="rectangle"> <gradient android:stairtColor="#f9f9f9" android:centerColor="#ffffff" android:endColor="#ffffff" android:angle="90"/> <stroke android:width="1dp" android:color="#2B547E"/> </shape> </item> </layer-list> 
    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.