2016-01-13 50 views
0

工具欄在Android 4.4和以前的版本中可見。當我在棒棒糖版本中安裝我的應用程序時,工具欄被框架佈局隱藏。如何解決這個問題?工具欄在棒棒糖中不可見?

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:orientation="vertical"> 
    <android.support.v4.widget.DrawerLayout  xmlns:android="http://schemas.android.com/apk/res/android" 
     xmlns:app="http://schemas.android.com/apk/res-auto" 
     xmlns:tools="http://schemas.android.com/tools" 
     android:id="@+id/drawer_layout" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:fitsSystemWindows="true" 
     tools:openDrawer="hide"> 
     <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
    android:orientation="vertical"> 
      <android.support.v7.widget.Toolbar 
      android:id="@+id/toolbar" 
      android:layout_width="match_parent" 
      android:layout_height="?attr/actionBarSize" 
      android:background="@color/white" 
     app:theme="@style/ThemeOverlay.AppCompat.ActionBar" 
     app:popupTheme="@style/ThemeOverlay.AppCompat.Light" 
    > 
</android.support.v7.widget.Toolbar> 

<FrameLayout 

    android:id="@+id/content_frame" 
    android:layout_below="@+id/toolbar" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" /> 

Java代碼:

Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); 
    setSupportActionBar(toolbar); 
    getSupportActionBar().setDisplayShowTitleEnabled(false); 
    getSupportActionBar().setDisplayHomeAsUpEnabled(true); 
    getSupportActionBar().setDisplayShowCustomEnabled(true); // enable overriding the default toolbar layout 
    getSupportActionBar().setDisplayShowTitleEnabled(false); 
+0

給予邊緣頂部到您的框架佈局,然後嘗試 –

+0

您可以添加'android:layout_height =「wrap_content」 android:minHeight =「?attr/actionBarSize」'Toolba r –

+1

我試過這個邏輯。我在kitkat中完美工作,但在棒棒糖中工作 – Gopal

回答

1

試試下面的代碼 -

<android.support.v4.widget.DrawerLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:id="@+id/drawer_layout" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:fitsSystemWindows="true" 
    tools:openDrawer="hide"> 

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

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

     <FrameLayout 

      android:id="@+id/content_frame" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" /> 

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

下創建RES /值-V21一款式/ style.xml

<resources> 

<style name="AppTheme.NoActionBar"> 
<item name="windowActionBar">false</item> 
<item name="windowNoTitle">true</item> 
<item name="android:windowDrawsSystemBarBackgrounds">true</item> 
<item name="android:statusBarColor">@android:color/transparent</item> 
</style> 

</resources> 
+0

否它不工作,它在kitkat罰款。 – Gopal

+0

@Gopal:你可以發佈圖像的區別? – kevz

+0

是的。我發佈了 – Gopal

1

更改您的根佈局設置爲RelativeLayout的,把的FrameLayout第一和一切而來的的FrameLayout

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="match_parent"> 

    <FrameLayout 

    android:id="@+id/content_frame" 
    android:layout_below="@+id/aaa" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" /> 

    <android.support.v4.widget.DrawerLayout  xmlns:android="http://schemas.android.com/apk/res/android" 
     xmlns:app="http://schemas.android.com/apk/res-auto" 
     xmlns:tools="http://schemas.android.com/tools" 
     android:id="@+id/drawer_layout" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:fitsSystemWindows="true" 
     tools:openDrawer="hide"> 
     <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
    android:orientation="vertical"> 
      <android.support.v7.widget.Toolbar 
      android:id="@+id/toolbar" 
      android:layout_width="match_parent" 
      android:layout_height="?attr/actionBarSize" 
      android:background="@color/white" 
     app:theme="@style/ThemeOverlay.AppCompat.ActionBar" 
     app:popupTheme="@style/ThemeOverlay.AppCompat.Light" 
    > 
</android.support.v7.widget.Toolbar> 
+0

不,它不工作在棒棒糖版本 – Gopal

0

使它看起來像這樣,我希望它的工作原理

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

</android.support.design.widget.AppBarLayout> 
相關問題