2017-03-28 32 views
0

我在活動的操作欄,聲明如下:Android操作欄上較舊的Android版本

protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.dashboard); 

    Toolbar myToolbar = (Toolbar) findViewById(R.id.toolbar); 
    setSupportActionBar(myToolbar); 
    getSupportActionBar().setDisplayShowTitleEnabled(false); 
    getSupportActionBar().setDisplayHomeAsUpEnabled(true); 
    getSupportActionBar().setHomeAsUpIndicator(R.drawable.hamburger); 

和我的XML:

<?xml version="1.0" encoding="utf-8"?> 
<android.support.v4.widget.DrawerLayout 
    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:id="@+id/activity_dashboard" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    tools:context="org.wega.mcfc.DashboardActivity" > 

    <!-- Main Content --> 
    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" > 

     <android.support.v7.widget.Toolbar 
      android:id="@+id/toolbar" 
      android:layout_width="match_parent" 
      android:layout_height="?attr/actionBarSize" 
      android:elevation="4dp" 
      android:background="@color/colorPrimary" 
      android:theme="@style/ThemeOverlay.AppCompat.ActionBar" 
      app:popupTheme="@style/ThemeOverlay.AppCompat.Light" /> 


     ... 
    </RelativeLayout> 
</android.support.v4.widget.DrawerLayout> 

我剛剛試過我的應用程序一個較舊的Android版本(4而不是6)和工具欄不再顯示,是否有其他事情我應該爲它工作?

回答

0

它支持工具欄佈局嗎?即

<android.support.design.widget.AppBarLayout 


android:theme="@style/AppTheme.AppBarOverlay"> 
... 
... 
<android.support.v7.widget.Toolbar 
    android:id="@+id/toolbar" 
    ... 
... /> 

+0

是的,它是在一個android.support.v4.widget.DrawerLayout一個RelativeLayout的一個android.support.v7.widget.Toolbar。 –

+0

你能告訴你toolbar.xml嗎? – AlexGuerra

+0

我沒有toolbar.xml,我編輯了我的問題以添加我的活動的xml。 –