1

Since I was using

EditText et=new EditText(this);
locationEditText.setBackgroundDrawable(et.getBackground());

but setBackgroundDrawable(Drwable) is deprecated in Api 16 as can't use setBackground(Drwable) since it was added in api 16 and I'm using earlier versions than that

So the only two functions left to me

are: setBackgroundColor(int color) and setBackgroundResource(int resid)

So how to set it to the default EditText in Holo Light Theme?

Cœur
  • 37,241
  • 25
  • 195
  • 267
Youans
  • 4,801
  • 1
  • 31
  • 57

3 Answers3

1

Use setBackground(Drawable drawable) that do the same job of setBackgroundDrawable(Drwable).

edit: thx to Warpzit for this code (source):

EditText et=new EditText(this);

int sdk = android.os.Build.VERSION.SDK_INT;
if(sdk < android.os.Build.VERSION_CODES.JELLY_BEAN) {
    setBackgroundDrawable(et.getBackground());
} else {
    setBackground(et.getBackground());
}

You can find more info in this question

Community
  • 1
  • 1
  • Can't this function isn't exist before Api 16 and my range of Apis is from 11-17 – Youans Aug 07 '13 at 10:18
  • Still the issue of how to set the background of the EditText in latest versions 16+ Apis to Holo Default EditText Theme – Youans Aug 07 '13 at 10:36
  • i'm sorry but i don't understand: _Still the issue of how to set the background of the EditText in latest versions 16+ Apis to Holo Default EditText Theme_. My code should work with just a warning advice. – Roberto Lombardini Aug 07 '13 at 10:53
0

This may help you

<EditText
    android:layout_height="wrap_content"
    android:layout_width="wrap_content"
    style="@android:style/Widget.Holo.EditText"/>
Hybrid Developer
  • 2,320
  • 1
  • 34
  • 55
0

My suggestion is to create a template layout xml file for edittext with the style you need assigned and inflate it when you need it in code. in XML

Use this in code:

EditText et = (EditText )getLayoutInflater().inflate(R.layout.edtemplate, null);

refereed more at android set style in code

Community
  • 1
  • 1
Niroshan
  • 1,174
  • 1
  • 12
  • 30