На изображении ниже находится серая область под моим списком и над моей кнопкой. Я хочу, чтобы эта область имела тот же цвет фона (черный), что и список.
Мне кажется странным, что в эмуляторе это черное, но на моем телефоне оно серое.
Я попытался установить цвет фона макета, списка и 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>
Любая помощь оценивается.
РЕДАКТИРОВАТЬ
Чтобы быть ясным, у меня нет проблем с этим списком, когда он заполняет экран, когда только несколько элементов, которые не заполняют экран, я получаю этот серый фон... Я бы предпочел, чтобы он был тем же черным фоном, что и список.
Посмотрев на свой скриншот, похоже, что ваш телефон работает под управлением Motorola 2. 3+ (Droid 3?). Я видел ту же "функцию" на некоторых телефонах Motorola.
Проверьте этот пост на Motorola Blog для получения полного ответа. В принципе, добавьте в атрибуты ListView
XML android:overScrollFooter="#000000"
.
Он работает только для устройств 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">
Я думаю, вы можете применить стиль непосредственно к списку, не проходя тему, но это решение будет работать для всех ListViews в вашем приложении, как только вы примените его ко всем вашим действиям в манифесте.
//это выглядит хорошо для меня
<?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>
Ну, не похоже, что список расширяет оставшееся пространство? Это предназначено?
Кроме того, чтобы изменить серый цвет, не нужно ли устанавливать цвет фона "пустого" текстового вида, поскольку он, по-видимому, охватывает всю высоту, я предполагаю, что текст выглядит серым.
Попробуйте это (я не уверен, что это решает вашу проблему...):
<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)