Dlaczego nie mogę znaleźć mojego Toolbar
w moim układzie?Pasek narzędzi - findViewbyID wraca null
setContentView(R.layout.activity_main);
toolbar = (Toolbar) findViewById(R.id.toolbar);
if (toolbar != null) {
setSupportActionBar(toolbar);
getSupportActionBar().setHomeButtonEnabled(true);
}
Po tym pasku narzędzi wciąż jest pusta.
activity_man.xml:
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false"
tools.context=".PlayerActivity">
<include
android:id="@+id/toolbar"
layout="@layout/toolbar"/>
<ImageView
android:id="@+id/background_image"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"/>
: (goes on)
EDIT:
toolbar.xml:
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"/>
Dzięki!
Co jest w 'res/layout/toolbar.xml'? 'R.id.toolbar' wskazuje na' ', a nie' Toolbar'. "W moim pasku narzędzi znajduje się tylko pasek narzędzi" - ale ten układ nie jest częścią twojego pytania, więc nie możemy zobaczyć jego zawartości. –
CommonsWare
Czy używasz 'setContentView' dla toolbar.xml? –
Zaktualizowany przez setcontenview i układ paska narzędzi. Grałem trochę, a teraz działa, ale pasek narzędzi nie jest widoczny na ekranie ?! –