Android如何获取LinearLayout的颜色 "style="@android :style/ButtonBar""

标签 android colors background android-linearlayout

我想以编程方式获取样式为“ButtonBar”的 LinearLayout 的背景颜色。

<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();

关于Android如何获取LinearLayout的颜色 "style="@android :style/ButtonBar"",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9856155/

相关文章:

bash - Grep - 循环显示每场比赛的颜色

iphone - iPhone中是否启用了背景音频播放?

android - 尝试在我的应用程序中创建塞子

android位图getPixel

javascript - 如何使用 Javascript/jQuery 计算 RGB 十六进制颜色变化

iphone - iOS 背景和图像似乎无法正确缩放以适应视网膜显示

swift - 如何让计时器在后台运行?

Android 对话框仅在第二次单击时关闭。为什么?

java - android中读取联系人的两个版本之间的冲突

android - Bouncy CaSTLe Keystore (BKS) : java. io.IOException: keystore 版本错误