简体   繁体   中英

How do I change the font colour on a ListView in Eclipse for Android?

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 =]

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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM