在XML布局的如下:
<pre name="code" class="html"><LinearLayout
android:id="@+id/outstock_lists"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#00000000"
android:gravity="center"
android:orientation="vertical" >
</LinearLayout>
给Linearlayout设置的背景色,即透明色
但是在deug模式中,在Linearlayout对象的mbackground属性值为ColorDrawable,那么如何在ColorDrawable中查看颜色值呢,通过分析源代码
public ColorDrawable(int color) {
this(null);
setColor(color);
}
public void setColor(int color) {
if (mState.mBaseColor != color || mState.mUseColor != color) {
invalidateSelf();
mState.mBaseColor = mState.mUseColor = color;
}
}
最终的颜色值被赋值到mState.mBaseColor属性上,在这个对象上面,看到的值是一个int类型(-8947849),自己还是不知道这个值代表的是什么颜色,最后查遍网络,发现了一个方法,可以把android 的颜色从int值转换成String类型,方式如下:
int intColor=-8947849;
String strColor = String.format("#%06X", 0xFFFFFF & intColor);
最终得到的颜色值是#777777
不是自己在Xml布局中设置的透明色
不知道是什么操作导致android没有加载在XML中定义的颜色,导致最后在加载时颜色值不是我想要的,不得已只能在加载布局之后,给Linearlayout的background再次赋值。