我应该调用什么方法来知道一个活动是否有它的contentView(一旦方法setContentView()被调用)?


当前回答

你也可以覆盖onContentChanged(),当setContentView()被调用时,onContentChanged()会被触发。

其他回答

如果您正在使用Kotlin

    this.findViewById<View>(android.R.id.content)
                         .rootView
                         .setBackgroundColor(ContextCompat.getColor(this, R.color.black))

您可能想尝试View.getRootView()。

你也可以覆盖onContentChanged(),当setContentView()被调用时,onContentChanged()会被触发。

this.getWindow().getDecorView().findViewById(android.R.id.content)

or

this.findViewById(android.R.id.content)

or

this.findViewById(android.R.id.content).getRootView()

如果你在布局中添加一个ID,你就可以得到视图。

<RelativeLayout
    android:id="@+id/my_relative_layout_id"

从findViewById调用它…