2016-12-06 121 views
0

我有一個簡單的佈局半透明狀態欄和ListView問題

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:orientation="vertical" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:fitsSystemWindows="true"> 

<ListView 
    android:id="@+id/list_view" 
    android:fitsSystemWindows="true" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" /> 

</LinearLayout> 

而且它看起來像這樣

Link to example image

但我想我的名單是狀態欄下。 像谷歌照片應用

Link to example image

我加android:fitsSystemWindows="true"我的ListView,但沒有得到期望的結果。

請幫助我實現像Google照片一樣的ListView行爲。

非常感謝。

回答

0

ListView與透明狀態欄無關。

如果你希望你的應用程序有一個透明的狀態欄,你需要實現這樣的

<!-- Make the status bar translucent --> 
<style name="AppTheme" parent="AppTheme.Base"> <!-- or some theme you are using--> 
    <item name="android:windowTranslucentStatus">true</item> 
</style> 

然後在你的活動你的風格,

// A method to find height of the status bar 
public int getStatusBarHeight() { 
    int result = 0; 
    int resourceId = getResources().getIdentifier("status_bar_height", "dimen", "android"); 
    if (resourceId > 0) { 
     height = getResources().getDimensionPixelSize(resourceId); 
    } 

    return height; 
} 

// in your onCreate 
@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.my_activity); 

    // Retrieve the AppCompact Toolbar 
    Toolbar toolbar = (Toolbar) findViewById(R.id.my_toolbar); 
    setSupportActionBar(toolbar); 

    // Set the padding to match the Status Bar height 
    toolbar.setPadding(0, getStatusBarHeight(), 0, 0); 
} 

大部分來源是:http://blog.raffaeu.com/archive/2015/04/11/android-and-the-transparent-status-bar.aspx

0

嘗試添加以下樣式您的活動正在使用(只會在api級別21或更高版本上工作)

<item name="android:windowDrawsSystemBarBackgrounds">true</item> 
    <item name="android:statusBarColor">@android:color/transparent</item>