set View Background resource - Android User Interface

Android examples for User Interface:View Background

Description

set View Background resource

Demo Code


//package com.java2s;
import android.app.Activity;

import android.support.annotation.DrawableRes;
import android.support.annotation.IdRes;

import android.view.View;

public class Main {
    public static void setBackground(@DrawableRes int drawableId,
            View parent, @IdRes int viewId) {
        View view = findView(parent, viewId);
        view.setBackgroundResource(drawableId);
    }//from   ww  w . j  a v  a 2  s  .  co  m

    public static <T extends View> T findView(View parent, @IdRes int viewId) {
        return (T) parent.findViewById(viewId);
    }

    public static <T extends View> T findView(Activity activity,
            @IdRes int viewId) {
        return (T) activity.findViewById(viewId);
    }
}

Related Tutorials