2013-12-24 4 views
2

Извините, если я повторяю вопрос.Цвет элемента списка очень слабый

Я читаю SMS/s из папки «Входящие» и показывая их в списке.

Я вижу SMS/s в списке как элемент списка после выполнения.

Проблема только в том, что цвет текста элемента listview отличается бледным (текст, который я получаю, не читается/видимый).

Я попытался изменить его, но ничего не произошло.

Как я могу изменить этот цвет на черный или на любой другой цвет?

Вот мой activity_view_task.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" > 

<TextView 
    android:id="@+id/tv_tasks" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentTop="true" 
    android:layout_centerHorizontal="true" 
    android:text="Tasks" 
    android:textAppearance="?android:attr/textAppearanceLarge" /> 

<ListView 
    android:id="@+id/lv_view_task" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_below="@+id/tv_tasks" 
    android:layout_centerHorizontal="true" 
    android:cacheColorHint="#000000" 
    android:textColor="#000000"> 

</ListView> 
</RelativeLayout> 

Вот мой Java-файл, откуда я добавляю элементы в ListView:

package com.example.myapp; 

import java.util.ArrayList; 
import java.util.List; 

import android.net.Uri; 
import android.os.Bundle; 
import android.app.Activity; 
import android.database.Cursor; 
import android.view.Menu; 
import android.widget.ArrayAdapter; 
import android.widget.ListView; 
import android.widget.TextView; 

public class ViewTask extends Activity { 

TextView tv_view_task; 
ListView lv_view_task; 
static String sms = ""; 
@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_view_task); 
    tv_view_task=(TextView) findViewById(R.id.tv_view_task); 
    lv_view_task=(ListView) findViewById(R.id.lv_view_task); 

    List<String> msgList = getSms(); 

    final ArrayAdapter<String> adapter = new ArrayAdapter<String>(getApplicationContext(),android.R.layout.select_dialog_singlechoice, msgList); 
     lv_view_task.setAdapter(adapter); 
} 


public List<String> getSms() { 
    List<String> labeles = new ArrayList<String>(); 
    Uri uri = Uri.parse("content://sms/inbox"); 
    Cursor c = getContentResolver().query(uri, null, null, null, null); 


    // Read the sms data and store it in the list 
    if (c.moveToFirst()) { 
     do { 
      String body = c.getString(c.getColumnIndex("body")); 
      String address = c.getString(c.getColumnIndex("address")); 
      sms = "From : " + address + " : " + body; 
      labeles.add(sms); 
     } while (c.moveToNext()); 
    } 
    c.close(); 

    return labeles; 
} 
@Override 
public boolean onCreateOptionsMenu(Menu menu) { 
    getMenuInflater().inflate(R.menu.activity_view_task, menu); 
    return true; 
} 

}

После выполнения это выглядит так:

enter image description here

+0

Не хочет заказной макет для ListView? – Piyush

+0

Можете ли вы разместить любой пример или ссылку для пользовательского макета для listview? – Rohhit

+0

см. Мой ответ .. – Piyush

ответ

2

Вам нужно будет создать пользовательский макет для элементов ListView, где вы установите нужную TextColor.

Таким образом, вам даже не нужен пользовательский адаптер .

например. custom_textview.xml

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="wrap_content" 
android:gravity="center" 
android:layout_height="wrap_content" 
> 
<TextView 
android:id="@+id/tv" 
android:textColor="@color/white" 
android:layout_width="fill_parent" 
android:gravity="center" 
android:layout_height="fill_parent"/> 
</LinearLayout> 

Затем вы можете использовать макет с ArrayAdapter:

ArrayAdapter<String> adapter = new ArrayAdapter<String>(MainActivity.this, R.layout.custom_textview, aa); 
lv.setAdapter(adapter); 
0

Добавьте это в activity_view_task.xml:

android:textColor="#000000" 
1

Сделать заказ Имя макета row_item.xml

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 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:orientation="vertical" 
    tools:ignore="HardcodedText,UselessParent" > 

    <LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="40dp" 
    android:orientation="horizontal" > 

    <TextView 
     android:id="@+id/tv" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center|left" 
     android:layout_marginLeft="10dp" 
     android:text="Medium Text" 
     android:textColor="#000000" 
     android:textAppearance="?android:attr/textAppearanceMedium" 
     android:textSize="16sp" /> 
    </LinearLayout> 
</LinearLayout> 

сделать пользовательский адаптер глобально подобный:

MyAdapter adp; 

Теперь инициализировать его на OnCreate() метод:

adp = new MyAdapter (YourActivity.this, yourArrayList); 


class MyAdapter extends BaseAdapter { 

    Context c; 
    String[] yourarraylist; 
    LayoutInflater mInflater; 

    public CustomAdapter(Context fullImage, String[] yourarraylist) { 
     // TODO Auto-generated constructor stub 
     this.c = fullImage; 
     this.yourarraylist= yourarraylist; 
     mInflater = LayoutInflater.from(c); 
    } 

    @Override 
    public int getCount() { 
     // TODO Auto-generated method stub 
     return yourarraylist.length; 
    } 

    @Override 
    public Object getItem(int position) { 
     // TODO Auto-generated method stub 
     return position; 
    } 

    @Override 
    public long getItemId(int position) { 
     // TODO Auto-generated method stub 
     return position; 
    } 

    @Override 
    public View getView(int position, View convertView, ViewGroup parent) { 
     // TODO Auto-generated method stub 

     if (convertView == null) { 
      convertView = mInflater.inflate(R.layout.row_item, parent, 
        false); 

      TextView tv = (TextView) convertView.findViewById(R.id.tv); 
      // set text here 
     } 
     return convertView; 
    } 

} 
Смежные вопросы