我的解决方案是创建一个自定义视图对象。这里的关键将覆盖onDraw函数,在该函数中只需在画布上绘制所需的颜色。它应该很容易。
请试试这个,让我知道,如果你有任何问题......这里有一些指点...
在视图对象...
public class MyView extends View {
@Override protected void onDraw(Canvas canvas) {
canvas.drawColor(mColor);
}
private int mColor = 0xff000000; //black
public void SetColor(int aColor) {
mColor = aColor;
invalidate(); //Not sure about this line, can't remember if this is the correct call... there is a call that causes a redraw
}
}
在你的活动布局XML。 ..
android:id="@+id/ClassName1"
android:layout_height="fill_parent"
android:layout_width="fill_parent"/>
在你的活动代码...
@Override public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.yourxmllayoutfile);
MyView aMyView = (MyView) findViewById(R.id.ClassName1);
aMyView.SetColor(0xff00ff00); //Green I think, this line changes the color
}
好运:)