2016-06-16 5 views
1

私は非常に興味深い問題を抱えています。 Androidのビューにツールバーを追加しましたが、以下の問題に直面したことはありません。ツールバーが何も応答していません

ツールバーに直接アクセスする場合、またはsetSupportActionBar(myToolbar)によって割り当てる場合ツールバー自体は変更できません。私はビューを設定することを試みたし、それは動作しませんでした。同様に、ツールバーには何も表示されません。アプリ名なし、ハンバーガーメニューなし、戻る矢印なし、何もありません。

下に掲示関連コード:

BaseActivity.java

@Nullable 
@BindView(R.id.app_bar) 
protected Toolbar mToolbar; 

private Unbinder unbinder; 

@Override 
protected void onCreate(@Nullable Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(getLayoutResource()); 
    unbinder = ButterKnife.bind(this); 

    if(mToolbar != null) { 
     Timber.tag("Toolbar").d("Toolbar is not null. Oh glorious day"); 
     setSupportActionBar(mToolbar); 
    } 
} 

base_drawer_activity.xml

<?xml version="1.0" encoding="utf-8"?> 
<android.support.design.widget.CoordinatorLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical"> 

    <android.support.v4.widget.DrawerLayout 
     android:id="@+id/drawer_layout" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:fitsSystemWindows="true"> 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:orientation="vertical" 
      android:fitsSystemWindows="true"> 

      <android.support.design.widget.AppBarLayout 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:fitsSystemWindows="true" 
       android:orientation="vertical"> 

       <include 
        android:id="@+id/app_bar" 
        layout="@layout/toolbar" /> 

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

      <FrameLayout 
       android:id="@+id/container_frame" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:clipToPadding="true"> 

      </FrameLayout> 

     </LinearLayout> 

     <android.support.design.widget.NavigationView 
      xmlns:android="http://schemas.android.com/apk/res/android" 
      android:id="@+id/navigation_view" 
      android:layout_width="wrap_content" 
      android:layout_height="match_parent" 
      android:layout_gravity="start" 
      android:fitsSystemWindows="true"/> 

    </android.support.v4.widget.DrawerLayout> 
</android.support.design.widget.CoordinatorLayout> 

toolbar.xml

<?xml version="1.0" encoding="utf-8"?> 
<android.support.v7.widget.Toolbar 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:id="@+id/toolbar" 
    android:layout_width="match_parent" 
    android:layout_height="?attr/actionBarSize" 
    android:background="@color/colorPrimary" 
    android:clipToPadding="true" 
    app:layout_collapseMode="pin" 
    app:layout_scrollFlags="scroll|enterAlways" 
    android:popupTheme="@style/ThemeOverlay.AppCompat.Light"/> 

のstyles.xml

<resources> 

    <!-- Base application theme. --> 
    <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar"> 
     <!-- Customize your theme here. --> 
     <item name="colorPrimary">@color/colorPrimary</item> 
     <item name="colorPrimaryDark">@color/colorPrimaryDark</item> 
     <item name="colorAccent">@color/colorAccent</item> 
     <item name="android:windowBackground">@color/colorDefaultBackground</item> 
    </style> 

</resources> 

私のマニフェスト内のアプリケーションタグはまたandroid:theme="@style/AppTheme"

を設定ツールバー自体がビューにnullでない(既にことを確認している) そしてそれましたサポートアクションバーを作成するのと同じ方法でプロジェクトを開いたので、SDK自体ではありません。

私は本当にここで何かが分かりませんか?

答えて

1

解決済み!

ちょっと見た後、私の子クラスが実際にsetContentと親クラスを呼び出していて、私が行ったビューの変更が上書きされていることがわかりました。

私の一部では簡単な見落としがあります。

関連する問題