2012-05-18 275 views
1

在下面的圖像是我的列表視圖下和我的按鈕上方的灰色區域。我希望該區域具有與列表相同的背景顏色(黑色)。背景顏色(列表視圖?)

什麼似乎很奇怪,我是在模擬器中它是黑色的,但我的手機上,這是這個灰色。

enter image description here

我試過設置佈局,列表和cachecolorhint的背景顏色...不管是什麼,它保持灰色。

當前佈局:

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="#000000" > 
    <TextView 
     android:id="@+id/header" 
     android:layout_width="fill_parent" 
     android:layout_height="27dp" 
     android:layout_alignParentTop="true" 
     android:layout_gravity="center|center_vertical" 
     android:gravity="center" 
     android:textColor="#00ccff" 
     android:textSize="20dp" /> 
    <TextView 
     android:id="@+id/horizontalline" 
     android:layout_width="match_parent" 
     android:layout_height="2dip" 
     android:layout_below="@id/header" 
     android:background="#8b8b8b" 
     android:paddingBottom="2dip" 
     android:paddingTop="2dip" /> 
    <Button 
     android:id="@+id/AddButton" 
     android:layout_width="match_parent" 
     android:layout_height="35dp" 
     android:layout_alignParentBottom="true" 
     android:layout_gravity="center" 
     android:gravity="center|top" 
     android:textSize="12dp" > 
    </Button> 
    <ListView 
     android:id="@id/android:list" 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_below="@id/horizontalline" 
     android:background="#000000" 
     android:cacheColorHint="#000000" 
     android:layout_above="@id/AddButton" 
     android:drawSelectorOnTop="false" 
     android:listSelector="@android:color/transparent" /> 
    <TextView 
     android:id="@android:id/empty" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_below="@id/header" 
     android:gravity="center" /> 
</RelativeLayout> 

任何幫助表示讚賞。

編輯

要清楚,我有一個列表中沒有問題,當它填補了屏幕,它的時候,那裏已經沒有填滿屏幕,我得到這個灰色的背景只有幾個項目...我更喜歡它與列表相同的黑色背景。

+0

give android:cacheColorHint =「#000000」as#00000000。那麼這個TextView的用途是什麼android:id =「@ android:id/empty」? –

+0

沒有。一樣。 – Barak

回答

8

看,它看起來像你的手機運行的摩托羅拉2.3+(Droid 3的?)。 我在摩托羅拉的某些手機上看到了相同的「功能」。

檢查this post on Motorola Blog一個完整的答案。 基本上,添加您的ListView XML屬性android:overScrollFooter="#000000"

它僅適用於2.3及更高版本的設備,所以你寧願把它放在一個風格res/values-v10/styles.xml

<style name="MyListView" parent="@android:style/Widget.ListView"> 
    <item name="android:listSelector">@drawable/list_selector</item> 
    <item name="android:overScrollFooter">#000000</item> 
</style> 

然後添加到您的theme.xml

<style name="MyTheme" parent="android:Theme"> 
    <item name="android:windowBackground">@null</item> 
    <item name="android:listViewStyle">@style/MyListView</item> 
</style> 

最後,您的申請定製主題到您的AndroidManifest活動中:

<activity android:name="com.listtest.MainActivity" 
    android:label="@string/app_name" 
    android:theme="@style/MyTheme"> 

I我們猜你可以將樣式直接應用到列表中,而無需傳遞主題,但只要將其應用於清單中的所有活動,此解決方案就可以在您的應用中適用於所有ListView。

+0

這看起來很有希望,而且這正是我遇到的問題。我回家時接受您的解決方案回答如果他們工作的話,謝謝! – Barak

+0

這確實是個問題,現在看起來好多了, – Barak

+1

哦,親愛的上帝,哇,這個工作經過數小時的打擊之後,我不必添加主題,只需指定頁腳顏色。感謝和贊成票! –

0

那麼,它不是像列表擴展的剩餘空間?這是打算嗎?

此外,要改變灰色,你不需要設置「空白」文本視圖的背景顏色,因爲它看起來跨越了整個高度,我猜這是顯示爲灰色的文本視圖。

+0

沒有。試圖將該文本視圖的背景設置爲黑色,列表下方的灰色相同。 – Barak

1

//這看起來對我罰款

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="#000000" > 
    <TextView 
     android:id="@+id/header" 
     android:layout_width="fill_parent" 
     android:layout_height="27dp" 
     android:layout_alignParentTop="true" 
     android:layout_gravity="center|center_vertical" 
     android:gravity="center" 
     android:textColor="#00ccff" 
     android:textSize="20dp" /> 
    <TextView 
     android:id="@+id/horizontalline" 
     android:layout_width="match_parent" 
     android:layout_height="2dip" 
     android:layout_below="@id/header" 
     android:background="#8b8b8b" 
     android:paddingBottom="2dip" 
     android:paddingTop="2dip" /> 
    <TextView 

     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_below="@id/header" 
     android:gravity="center" 
     android:background="#000" 
     /> 
    <Button 
     android:id="@+id/AddButton" 
     android:layout_width="match_parent" 
     android:layout_height="35dp" 
     android:layout_alignParentBottom="true" 
     android:layout_gravity="center" 
     android:gravity="center|top" 
     android:textSize="12dp" > 
    </Button> 
    <ListView 
     android:id="@id/android:list" 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_below="@id/horizontalline" 
     android:background="#000000" 
     android:cacheColorHint="#000000" 
     android:layout_above="@id/AddButton" 
     android:drawSelectorOnTop="false" 
     android:listSelector="@android:color/transparent" /> 
</RelativeLayout> 
+0

我不清楚列表(本身)是否有問題......當它不填滿整個屏幕時,它就是它下面的區域。 – Barak

+0

@Barak編輯答案試試這一次。 –

+0

不幸的是,仍然灰色。 – Barak

0

試試這個(我不知道這樣做是否解決您的問題...):

<ListView 
    android:id="@+id/my_list" 
    android:layout_width="match_parent" 
    android:layout_height="fill_parent" 
    android:layout_below="@id/horizontalline" 
    android:background="#000000" 
    android:cacheColorHint="#000000" 
    android:layout_above="@id/AddButton" 
    android:drawSelectorOnTop="false" 
    android:listSelector="@android:color/transparent" /> 

(該列表視圖的高度應在你的屏幕截圖總是FILL_PARENT)

+0

不,在列表視圖下仍然會出現灰色區域,但它不會填滿屏幕。 – Barak