Android examples for User Interface:View Background
get View Background Color
//package com.java2s; import android.graphics.drawable.ColorDrawable; import android.graphics.drawable.Drawable; import android.view.View; public class Main { public static int getBackgroundColor(View view) { Drawable background = view.getBackground(); if (background == null) { throw new NullPointerException("background is null"); }/*from w w w .jav a2s.c om*/ if (background instanceof ColorDrawable) { final int backgroundColor = ((ColorDrawable) background) .getColor(); return backgroundColor; } else { throw new RuntimeException("background isn't ColorDrawable"); } } }