내 레이아웃에서 내 Toolbar
을 찾지 못하는 이유는 무엇입니까?툴바 - null을 반환하는 findViewbyID
setContentView(R.layout.activity_main);
toolbar = (Toolbar) findViewById(R.id.toolbar);
if (toolbar != null) {
setSupportActionBar(toolbar);
getSupportActionBar().setHomeButtonEnabled(true);
}
그 후, 툴바는 여전히 null입니다.
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)
편집 :
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"/>
감사합니다!
은 무엇입니까 사용하여 작업 표시 줄을
전면에 도구 모음을 가져와을 제거 styles.xml에서 다음 'res/layout/toolbar.xml'에 있습니까? 'R.id.toolbar'가'Toolbar'가 아니라''을 가리키고 있습니다. "내 툴바 레이아웃에는 툴바 만 있습니다"-하지만이 레이아웃은 질문의 일부가 아니기 때문에 내용을 볼 수 없습니다. –
CommonsWare
toolbar.xml에'setContentView'를 사용하고 있습니까? –
setcontenview 및 도구 모음 레이아웃으로 업데이트되었습니다. 조금 놀았지만 이제는 작동하지만 툴바가 화면에 보이지 않습니다. –