set Drawable to TextView - Android User Interface

Android examples for User Interface:TextView

Description

set Drawable to TextView

Demo Code


//package com.java2s;
import android.graphics.drawable.Drawable;
import android.widget.TextView;

public class Main {
    public static void setDrawable(TextView view, Drawable left,
            Drawable top, Drawable right, Drawable bottom) {
        if (left != null) {
            left.setBounds(0, 0, left.getMinimumWidth(),
                    left.getMinimumHeight());
        }//from   w  w  w .j a  v  a  2  s  .co  m

        if (top != null) {
            top.setBounds(0, 0, top.getMinimumWidth(),
                    top.getMinimumHeight());
        }

        if (right != null) {
            right.setBounds(0, 0, right.getMinimumWidth(),
                    right.getMinimumHeight());
        }

        if (bottom != null) {
            bottom.setBounds(0, 0, bottom.getMinimumWidth(),
                    bottom.getMinimumHeight());
        }

        view.setCompoundDrawables(left, top, right, bottom);
    }
}

Related Tutorials