回答:
this.getWindow().getDecorView().findViewById(android.R.id.content)
または
this.findViewById(android.R.id.content)
または
this.findViewById(android.R.id.content).getRootView()
setContentView(R.layout.my_view)返されます。
レイアウトにIDを設定すると、ビューを元に戻すことができます。
<RelativeLayout
android:id="@+id/my_relative_layout_id"
そして、findViewByIdから呼び出します...
findViewByIdますか?
いかがですか
View view = Activity.getCurrentFocus();
currentFocus?.let { ... }
Kotlin this.findViewById<View>(android.R.id.content)
.rootView
.setBackgroundColor(ContextCompat.getColor(this, R.color.black))
「isContentViewSet」メソッドはありません。次のように、setContentViewの前にtry / catchブロックにダミーのrequestWindowFeature呼び出しを配置できます。
{を試す
requestWindowFeature(Window.FEATURE_CONTEXT_MENU);
setContentView(...)
}キャッチ(AndroidRuntimeException e){
//何もしないか何もしない
}
コンテンツビューがすでに設定されている場合、requestWindowFeatureは例外をスローします。
私が見つけた最も邪魔にならない最善のオプションは、次のようにタグパラメータをxmlに設定することです
電話XMLレイアウト
<android.support.v4.view.ViewPager xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:tag="phone"/>
タブレットXMLレイアウト
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:tag="tablet">
...
</RelativeLayout>
アクティビティクラスでこれを呼び出します。
View viewPager = findViewById(R.id.pager);
Log.d(getClass().getSimpleName(), String.valueOf(viewPager.getTag()));
それがあなたのために働くことを願っています。
getWindow().findViewById(android.R.id.content):)