Yanıtlar:
this.getWindow().getDecorView().findViewById(android.R.id.content)
veya
this.findViewById(android.R.id.content)
veya
this.findViewById(android.R.id.content).getRootView()
setContentView(R.layout.my_view), bu düzenin üst öğesi döndürülür .
Mizanpajınıza bir kimlik koyarsanız görünümü Geri alabilirsiniz.
<RelativeLayout
android:id="@+id/my_relative_layout_id"
Ve findViewById'den arayın ...
findViewById?
Ayrıca onContentChanged(), setContentView()çağrıldığında tetiklenen diğerlerinin arasında geçersiz kılabilirsiniz .
Kotlin this.findViewById<View>(android.R.id.content)
.rootView
.setBackgroundColor(ContextCompat.getColor(this, R.color.black))
"İsContentViewSet" yöntemi yoktur. SetContentView'ı aşağıdaki gibi denemeden önce try / catch bloğuna kukla requestWindowFeature çağrısı koyabilirsiniz:
Deneyin {
requestWindowFeature (Window.FEATURE_CONTEXT_MENU);
setContentView (...)
} catch (AndroidRuntimeException e) {
// bir şey yapmak
}
İçerik görünümü önceden ayarlanmışsa, requestWindowFeature bir istisna atar.
Bulduğum en iyi seçenek ve daha az müdahaleci, xml'nizde bir etiket parametresi ayarlamaktır.
TELEFON XML DÜZENİ
<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"/>
TABLET XML DÜZENİ
<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>
ve bunu aktivite sınıfınızda arayın:
View viewPager = findViewById(R.id.pager);
Log.d(getClass().getSimpleName(), String.valueOf(viewPager.getTag()));
Umarım sizin için çalışır.
getWindow().findViewById(android.R.id.content):)