ビューのBackgroundColorを取得する
ボタンやレイアウトなどのビューのBackgroundを色で指定し、その色を後から動的に取得する方法です。
View v = target; // 対象のビューです。 ColorDrawable colorDrawable = (ColorDrawable) v.getBackground(); int colorInt = colorDrawable.getColor();
変数colorIntに、整数で格納されています。
いったんColorDrawableとして取得してから、getColor()で色を表す整数にしています。
getBackgroundColorのようなメソッドがあれば簡単なのですが・・・