Android examples for User Interface:View Background
set View Background resource
//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); } }