2016-08-12 8 views
1

Я не могу получить Toolbar для отображения. Я все сделала. Я не новичок в разработке Android.
Я использовал setSupportActionBar().
Я попытался отладить и посмотреть, нет ли getSupportActionBar(). И это пусто.
Я не знаю, почему это так. Я испытывал это, так как начал использовать Android DataBinding.Панель инструментов не видна в привязке данных

Это все, что я сделал:

binding = DataBindingUtil.setContentView(this, R.layout.activity_create); 
createBinding = DataBindingUtil.setContentView(this, R.layout.content_create); 

setSupportActionBar(binding.createToolbar); 

if (getSupportActionBar() != null) { 
    getSupportActionBar().setDisplayHomeAsUpEnabled(true); 
    String action = getIntent().getStringExtra("action"); 
    if (action != null) { 
     if (action.equals("create")) { 
      getSupportActionBar().setTitle(R.string.create); 
     } else { 
      getSupportActionBar().setTitle(R.string.update); 
     } 
    } 
} 

И мой XML

<?xml version="1.0" encoding="utf-8"?> 
    <layout xmlns:android="http://schemas.android.com/apk/res/android" 
     xmlns:bind="http://schemas.android.com/apk/res-auto"> 

     <data> 
      <import type="java.util.List"/> 
      <variable 
       name="customer" 
       type="co.company.Create.Customer"/> 
     </data> 

     <android.support.design.widget.CoordinatorLayout 
      xmlns:app="http://schemas.android.com/apk/res-auto" 
      xmlns:tools="http://schemas.android.com/tools" 
      android:orientation="vertical" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      tools:context=".CreateActivity"> 

      <android.support.design.widget.AppBarLayout 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:theme="@style/AppTheme.AppBarOverlay" 
       android:background="@color/transparent"> 

       <android.support.v7.widget.Toolbar 
        android:id="@+id/createToolbar" 
        android:layout_width="match_parent" 
        android:layout_height="?attr/actionBarSize" 
        android:background="@color/colorPrimaryDark" 
        app:popupTheme="@style/AppTheme.PopupOverlay" 
        app:layout_scrollFlags="scroll|enterAlways" /> 

      </android.support.design.widget.AppBarLayout> 

      <include layout="@layout/content_create" 
       android:id="@+id/contentCreateHolder" 
       bind:customer="@{customer}"/> 

     </android.support.design.widget.CoordinatorLayout> 
    </layout> 
+1

Почему вы называете 'DataBindingUtil.setContentView' дважды? Второй вызов может удалить «createToolbar» из Activity. – nshmura

ответ

2

Вы уверены, что хотите, чтобы ваш вид контента просто быть этот макет?

<include layout="@layout/content_create" 
    android:id="@+id/contentCreateHolder" 
    bind:customer="@{customer}"/> 

Если нет, удалите эту строку

createBinding = DataBindingUtil.setContentView(this, R.layout.content_create); 
+1

Это один из черт лица. Спасибо –

Смежные вопросы