Programmatically create textview background from drawable in Android

You need to use setBackgroundResource() method.

For example :

best_deals.setBackgroundResource(R.drawable.headerradius);

More about setBackgroundResource().


The Final code that worked

The older API than JELLYBEAN have different way to load drawable programatically. Try this:

       final int sdk = android.os.Build.VERSION.SDK_INT;
        if(sdk < android.os.Build.VERSION_CODES.JELLY_BEAN) {
            textView.setBackgroundDrawable(getResources().getDrawable(R.drawable.shape_rect_outline));
        } else {
            textView.setBackground(getResources().getDrawable(R.drawable.shape_rect_outline));
        }