Android如何获得LinearLayout的颜色;风格=“@android:style/ButtonBar“&引用;

Android如何获得LinearLayout的颜色;风格=“@android:style/ButtonBar“&引用;,android,colors,background,android-linearlayout,Android,Colors,Background,Android Linearlayout,我想以编程方式获得样式为“ButtonBar”的线性布局的背景色 <LinearLayout android:id="@+id/buttonBar" style="@android:style/ButtonBar" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="horizontal" > 我尝试使用Li

我想以编程方式获得样式为“ButtonBar”的线性布局的背景色

<LinearLayout
    android:id="@+id/buttonBar"
    style="@android:style/ButtonBar"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="horizontal" >

我尝试使用LinearLayout的getBackgroundColor,但没有找到方法

有人有主意吗? 问候

试试这个:

LinearLayout layout = (LinearLayout)findViewById(R.id.buttonBar);

PaintDrawable d = (PaintDrawable)layout.getBackground();
Paint paint = d.getPaint();
int color = paint.getColor();

不获取条颜色只需简单地插入背景颜色及其工作:)
style="@android:style/ButtonBar"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal" 
android:background="#CCCC99">