0

I'm making an app that needs to be easily read in the dark. By default, the screen is white, and this can be tough on the eyes of the user. The main activity that the user sees to start off with is called Menu, and I would like this to have a black background all over, with white text. I have everything how I want colour-wise, except for my ListView, where it looks black, but I cannot see the text because the background is black as well.

menu.xml:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:background="#000000"
    tools:context=".MainActivity" xmlns:app="http://schemas.android.com/apk/lib/com.google.ads">

    <TextView
        android:id="@+id/SelectSong"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@android:id/list"
        android:layout_alignTop="@+id/ic_launcher"
        android:text="@string/SelectSong"
        android:textSize="20sp"
        android:textColor="#FFFFFF" />

    <ListView
        android:id="@android:id/list"
        android:layout_width="wrap_content"
        android:layout_height="320dp"
        android:layout_above="@+id/settings_button"
        android:layout_below="@+id/ic_launcher"
        android:textColor="#FFFFFF"
        tools:listitem="@android:layout/simple_list_item_1" >

    </ListView>

    <ImageView
        android:id="@+id/ic_launcher"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_alignParentTop="true"
        android:contentDescription="@string/ic_launcher"
        android:src="@drawable/ic_launcher" />

    <ImageButton
        android:id="@+id/settings_button"
        android:src="@drawable/settings_button_selected"
        android:contentDescription="@string/action_settings"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true" />

    <ImageButton
        android:id="@+id/exit_button"
        android:src="@drawable/exit_button_selected"
        android:contentDescription="@string/exit"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentRight="true" />

</RelativeLayout>

Menu.java:

package com.lmarshall1995.scoutsongs;

import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ImageButton;
import android.widget.ListView;

public class Menu extends ListActivity{

    String classes[] = {"......"};

    String items[] = {"......"};

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.menu);

        final ImageButton settings = (ImageButton) findViewById(R.id.settings_button);
        settings.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                ......
            }
        });

        final ImageButton back = (ImageButton) findViewById(R.id.exit_button);
        back.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                ......
            }
        });

        setListAdapter(new ArrayAdapter<String>(Menu.this, android.R.layout.simple_list_item_1, items));
    }

    @Override
    protected void onListItemClick(ListView l, View v, int position, long id) {
        super.onListItemClick(l, v, position, id);
        String song_activity = classes[position];
        try{
        Class<?> ourClass = Class.forName("com.lmarshall1995.scoutsongs." + song_activity);
        Intent ourIntent = new Intent(Menu.this, ourClass);
        startActivity(ourIntent);
        }catch(ClassNotFoundException e){
            e.printStackTrace();
        }
    }

}

Please can someone show me how I need to change my code in order to make this work? - I have removed any code that is unnecessary to share by putting "......".

Thank you, From Laurence =]

  • Complete overkill manually changing each widget's color when you could just set your entire apps theme to a dark theme. – dymmeh Dec 19 '13 at 20:29
  • possible duplicate of [Android ListView Text Color](http://stackoverflow.com/questions/4533440/android-listview-text-color) – Nathaniel D. Waggoner Dec 19 '13 at 20:31
  • Based on @dymmeh's comments, perhaps you should check out this answer http://stackoverflow.com/questions/4663752/switching-application-wide-theme-programmatically – Jimi Dec 19 '13 at 20:34
  • @dymmeh I do not wish to do this, as my app can currently support Android versions 1.0 and above, and I would like to keep it that way. – Laurence Marshall Dec 19 '13 at 20:42
  • In your `ListView` you're using `tools:listitem="@android:layout/simple_list_item_1"`, that is using the default simple list item from the Android namespace. You would want to create your own list item xml... or you would have to override the adapter... – Tonithy Dec 19 '13 at 20:46
  • @Tonithy thought it would be something like that. How do I override the adapter? Thanks – Laurence Marshall Dec 19 '13 at 20:48
  • @LaurenceMarshall - Themes can be applied to all versions of android. You obviously won't have access to the newer themes like holo light and holo dark on older devices. You'd need to define your own theme and specify background color + text colors. Much easier to define it in one place (styles.xml) than to scatter hard coded colors throughout your entire app. – dymmeh Dec 19 '13 at 20:49
  • @dymmeh Thank you very much. :-) Sorted. – Laurence Marshall Dec 19 '13 at 21:03
  • @LaurenceMarshall you could subclass `BaseAdapter` then use that with your custom list item, but in getView you would need to inflate the view to the convert view. – Tonithy Dec 20 '13 at 00:08

1 Answers1

0

You can add a dark background to the List view. down load a black png image and place in the drawable folders.Example is show

android:background="@drawable/some_black_image"



<ListView
        android:id="@android:id/list"
        android:layout_width="wrap_content"
        android:layout_height="320dp"
        android:layout_above="@+id/settings_button"
        android:layout_below="@+id/ic_launcher"
        android:textColor="#FFFFFF"
        android:background="@drawable/some_black_image"
        tools:listitem="@android:layout/simple_list_item_1" >
</ListView>
Joseph
  • 1
  • 1