0

我有DrawerLayout和ListView活性作爲導航抽屜:導航抽屜列表視圖透明

<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@+id/drawer_layout" 
android:layout_width="match_parent" 
android:layout_height="match_parent"> 
<RelativeLayout 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"></RelativeLayout> 
<ListView 
    android:id="@+id/left_drawer" 
    android:layout_width="240dp" 
    android:layout_height="match_parent" 
    android:layout_gravity="start" 
    android:choiceMode="singleChoice" 
    android:dividerHeight="1dip" 
    android:divider="@drawable/gradient" /> 

活性已經施加到其在OnCreate成功設置(基於偏好亮或暗)全息主題,但該列表視圖是透明的,我可以看到它背後。

如何讓listview與佈局的其餘部分具有相同的主題? ListView的項目有這樣的佈局:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="wrap_content" 
android:paddingTop="1dip" 
android:paddingBottom="1dip" 
android:paddingLeft="3dp"> 
<ImageView 
    android:id="@+id/icon" 
    android:layout_width="32dip" 
    android:layout_height="32dip" 
    android:src="@drawable/job_history" 
    android:layout_gravity="center_vertical" /> 
<TextView 
    android:id="@android:id/text1" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:textAppearance="?android:attr/textAppearanceListItemSmall" 
    android:gravity="center_vertical" 
    android:paddingLeft="16dp" 
    android:paddingRight="16dp" 
    android:textColor="#fff" 
    android:background="?android:attr/activatedBackgroundIndicator" 
    android:minHeight="?android:attr/listPreferredItemHeightSmall" 
    android:text="this it a title" /> 

回答

1

使用android:background。我的導航抽屜有一個ListView和我應用

android:background="#f1f1f1" 

在LinearLayout上使用它也應該這樣做。

+0

如果我指定的背景一樣,它會在光亮和黑暗的主題,這是不是我想要的顏色相同。 – Giorgi

+0

您可以通過代碼linear.setBackgroundColor,根據您的主題設置背景顏色 – user666

+0

除了對代碼中的顏色進行硬編碼之外,還有其他方法嗎? – Giorgi

0

我會推薦給你的ListView背景

<ListView 
    android:id="@+id/left_drawer" 
    android:layout_width="240dp" 
    android:layout_height="match_parent" 
    android:layout_gravity="start" 
    android:choiceMode="singleChoice" 
    android:dividerHeight="1dip" 
    android:divider="@drawable/gradient" 
    android:background="@color/list_background" /> 
0

你可以只使用:

android:background="?android:windowBackground" 

,並應用此到您的列表,所以你的列表將始終使用在指定的窗口背景目前應用的主題。沒有硬編碼,沒有編碼,只是造型。 例如: -

<ListView android:background="?android:windowBackground" 
    android:id="@+id/list_drawer_start" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    />