2

如何获取活动背景颜色?当我使用

//View activityLayout = getActivityLayout();
((PaintDrawable) activityLayout.getBackground()).getPaint().getColor();

我得到异常:ColorDrawable 不能转换为 PainrDrawable。

4

1 回答 1

1

1st 获取活动的处理程序获取使用的根布局的句柄,然后在其上设置背景颜色。根布局是您调用的任何内容setContentView

setContentView(R.layout.main);

  // Now get a handle to any View contained 
  // within the main layout you are using
  View someView = findViewById(R.id.randomViewInMainLayout);

  // Find the root view
  View root = someView.getRootView()

  // Set the color
  root.setBackgroundColor(android.R.color.red);

或者你可以在你的活动中使用它

getWindow().getDecorView().setBackgroundColor(Color.WHITE);
于 2013-01-29T13:38:48.260 回答