2016-10-22 80 views
0

我有一個導航抽屜模板。我修改了操作欄,所以我沒有看到標題。我知道如何改變顏色,但我不知道如何獲得這樣的效果:Android Studio - 透明操作欄 - 導航抽屜

enter image description here

這是我目前的狀態:

enter image description here

這是我的styles.xml (我使用的Teme什麼):

<resources> 

<!-- Base application theme. --> 
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"> 
    <!-- Customize your theme here. --> 
    <item name="colorPrimary">@color/colorPrimary</item> 
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item> 
    <item name="colorAccent">@color/colorAccent</item> 
</style> 
<style name="AppTheme.NoActionBar"> 
    <item name="windowActionBar">false</item> 
    <item name="windowNoTitle">true</item> 
</style> 
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" /> 
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" /> 

回答

0

您可以使用具有透明背景的Toolbar

activity_main.xml中

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:id="@+id/activity_main" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <LinearLayout 
     android:id="@+id/your_content" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:background="#4BAE4F" 
     android:orientation="vertical"> 

     <!--Place your content here--> 

    </LinearLayout> 

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

    </android.support.v7.widget.Toolbar> 

</RelativeLayout> 

MainActivity.java

public class MainActivity extends AppCompatActivity { 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 

     setSupportActionBar((Toolbar) findViewById(R.id.toolbar)); 
    } 
} 

styles.xml

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar"> 
     <item name="colorPrimary">@color/colorPrimary</item> 
     <item name="colorPrimaryDark">@color/colorPrimaryDark</item> 
     <item name="colorAccent">@color/colorAccent</item> 

    </style> 

在API 19中,您可以在styles.xml中設置參數<item name="android:windowTranslucentStatus">true</item>以使狀態欄也是透明的。

+0

我嘗試過,但應用程序不斷崩潰。是否有另一種方法來獲得這種效果,還是我必須重新啓動整個應用程序? – Ivan

+0

檢查logcat輸出以知道崩潰的原因。還要確保你將AppTheme的父項設置爲'Theme.AppCompat.Light.NoActionBar'。 – dzikovskyy