我正在尝试以编程方式设置 UI 元素。
我可以在onWindowFocusChanged方法中设置 UI 元素吗?
我想问的问题是 - 我应该在onCreate方法还是onWindowFocusChanged中设置 UI 元素?编码 -
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.baselayout);
}
和
@Override
public void onWindowFocusChanged(boolean hasFocus) {
// TODO Auto-generated method stub
super.onWindowFocusChanged(hasFocus);
if (hasFocus) {
res = getResources();
inflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
setUpBackgroundImage();// setting up the background image
setUpTopMenu(); // Setting up the menu on top
setUpLogo(); // Setting up the Logo
}
}
上述方法是否正确?