之前看別人設置 把onCreate方法重寫了
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
LayoutInflater layoutInflater = (LayoutInflater) getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
LinearLayout ll = (LinearLayout) layoutInflater.inflate(R.layout.activity_main, null);
ll.setBackgroundColor(color.black);
setContentView(R.layout.activity_main);
}
想把背景顏色設為黑色,但還是白色沒變的
希望好心的大神解答一下 謝謝啦~~~
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
LayoutInflater layoutInflater = (LayoutInflater) getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
LinearLayout ll = (LinearLayout) layoutInflater.inflate(R.layout.activity_main, null);
ll.setBackgroundColor(color.black);
setContentView(R.layout.activity_main);//這裡初始化的ll不是你上面設置的ll,裡面會重新根據xml的內容生成布局的。
}
改成
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
LinearLayout ll = (LinearLayout) findViewById(R.layout.activity_main);
ll.setBackgroundColor(color.black);
}