Risposte:
this.getWindow().getDecorView().findViewById(android.R.id.content)
o
this.findViewById(android.R.id.content)
o
this.findViewById(android.R.id.content).getRootView()
setContentView(R.layout.my_view), questo restituisce il genitore di quel layout.
È possibile ottenere la visualizzazione Indietro se si inserisce un ID nel layout.
<RelativeLayout
android:id="@+id/my_relative_layout_id"
E chiamalo da findViewById ...
findViewById?
Kotlin this.findViewById<View>(android.R.id.content)
.rootView
.setBackgroundColor(ContextCompat.getColor(this, R.color.black))
Non esiste un metodo "isContentViewSet". È possibile inserire una richiesta fittiziaWindowFeature call in try / catch block prima di setContentView in questo modo:
provare {
requestWindowFeature (Window.FEATURE_CONTEXT_MENU);
setContentView (...)
} catch (AndroidRuntimeException e) {
// fai smth o niente
}
Se la visualizzazione del contenuto era già impostata, requestWindowFeature genererà un'eccezione.
L'opzione migliore che ho trovato e meno invadente, è impostare un parametro param nel tuo XML, come
LAYOUT XML DEL TELEFONO
<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"/>
LAYOUT XML DELLA TAVOLETTA
<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>
e quindi chiamalo nella tua classe di attività:
View viewPager = findViewById(R.id.pager);
Log.d(getClass().getSimpleName(), String.valueOf(viewPager.getTag()));
Spero che funzioni per te.
getWindow().findViewById(android.R.id.content):)