2016-12-06 11 views
0

私はシンプルなレイアウト半透明のステータスバーとリストビュー問題

<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

のように見えますが、私は私のリストには、ステータスバーの下にあったたいと思います。 などのGoogleでの写真アプリ

Link to example image

私は私のListViewへandroid:fitsSystemWindows="true"を追加しましたが、何の目的の結果を得ませんでした。

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> 
関連する問題