2012-05-17 83 views
6

Tôi có nền trắng nhưng với bố cục này, tôi bị chặn bởi vì màu văn bản cũng màu trắng và tôi không thể tìm thấy giải pháp để làm cho màu đỏ để tôi có thể đặt nền trắng, bất kỳ trợ giúp nào (như bạn có thể thấy tôi buộc phải sử dụng nền màu đỏ của cô ấy để tôi có thể thấy văn bản màu trắng).Thay đổi màu văn bản

public class QueueListActivity extends ListActivity { 
// LIST OF ARRAY STRINGS WHICH WILL SERVE AS LIST ITEMS 
ArrayList<String> listItems = new ArrayList<String>(); 
String newtext; 
String listFiles; 
// DEFINING STRING ADAPTER WHICH WILL HANDLE DATA OF LISTVIEW 
ArrayAdapter<String> adapter; 

// RECORDING HOW MUCH TIMES BUTTON WAS CLICKED 
int clickCounter = 0; 

ArrayList<String> selectedItems = new ArrayList<String>(); 


@Override 
public void onCreate(Bundle icicle) { 
    super.onCreate(icicle); 
    setContentView(R.layout.queuelistactivity); 
    Bundle extras1 = getIntent().getExtras(); 
    listFiles=GetFiles(); 

    StringTokenizer tokonizer1 = new StringTokenizer(listFiles,";"); 
    while(tokonizer1.hasMoreElements()){ 
     Log.i("verif","0"); 
     listItems.add(tokonizer1.nextToken());} 
      initializeListItems(); 



    if (extras1 != null) { 
     newtext = extras1.getString("newitem"); 
     listItems.add(newtext); 
     adapter.notifyDataSetChanged(); 
     getListView().setItemChecked(listItems.size() - 1, false); 

    } 




} 



// METHOD WHICH WILL HANDLE DYNAMIC INSERTION 
public void addItems(View v) { 

    Intent intent = new Intent(QueueListActivity.this, AjouterFiles.class);  
    QueueListActivity.this.startActivity(intent); 


    /* 
    listItems.add(userName); 
    adapter.notifyDataSetChanged(); 
    getListView().setItemChecked(listItems.size() - 1, false);*/ 


} 

public void deleteItems(View v) { 
    String toDelete = ""; 
    SparseBooleanArray sp = getListView().getCheckedItemPositions(); 

    for (int i = 0; i < sp.size(); i++) { 
     toDelete += ";" + sp.get(i); 
     if (sp.get(i)) { 
      listItems.remove(i); 
     } 

    } 
    adapter.notifyDataSetChanged(); 
    Toast.makeText(getApplicationContext(), toDelete, Toast.LENGTH_LONG).show(); 
    initializeListItems(); 
} 

private void initializeListItems() { 
    adapter = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_multiple_choice, listItems); 
    setListAdapter(adapter); 
    ListView lv = getListView(); 
    lv.setCacheColorHint(Color.rgb(0, 0, 0)); 
    lv.setBackgroundColor(Color.rgb(178, 34, 34)); 


    for (int i = 0; i < lv.getCount(); i++) { 
     lv.setItemChecked(i, false); 
    } 
} 
+0

sao chép ur tập tin xml đây – Abhinai

Trả lời

11

lừa tốt nhất là bạn sao chép file layout nội dung từ android.R.layout.simple_list_item_multiple_choice và làm cho bố cục của riêng bạn (my_list_view và chỉnh sửa tệp xml và thay đổi màu văn bản.

adapter = new Arr ayAdapter (this, my_list_view, listItems);

Chỉnh sửa tệp này dưới dạng my_list_view;

<CheckedTextView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@android:id/text1" 
    android:layout_width="match_parent" 
    android:layout_height="?android:attr/listPreferredItemHeight" 
    android:textAppearance="?android:attr/textAppearanceLarge" 
    android:gravity="center_vertical" 
    android:checkMark="?android:attr/listChoiceIndicatorMultiple" 
    android:paddingLeft="6dip" 
    android:paddingRight="6dip" 
    android:backdround="#FFFFFF" //white background 
    android:textColor="#000000" //black color text 
/> 
+0

Tôi có thể tìm android.R.layout.simple_list_item_multiple_choice bằng cách nào? –

+1

bạn chỉ có thể Ctrl + mousehover trên android.R.layout.simple_list_item_multiple_choice .. nhưng tôi đã dán mã đó thấy lỗi – vnshetty

+0

: Lỗi: Loại chuỗi không được phép (tại 'layout_width' có giá trị 'match_parent'). –

1

Bạn có thể đặt nó trong cách bố trí XML:

<TextView 
... 
... 
android:textColor="#FF0000" > 
</TextView> 

Hoặc cách lập trình:

textview.setTextColor(Color.RED); 
//textview must be defined in your class 
+1

nếu bạn có thể nhìn thấy tôi không có một TextView !! –

0

tốt hơn để viết adpter tùy chỉnh.

thay thế nhưng không soltuon tốt là sử dụng bố trí này xml inspace của android.R.layout.simple_list_item_multiple_choice

<CheckedTextView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@android:id/text1" 
    android:layout_width="match_parent" 
    android:layout_height="?android:attr/listPreferredItemHeight" 
    android:textAppearance="?android:attr/textAppearanceLarge" 
    android:gravity="center_vertical" 
    android:checkMark="?android:attr/listChoiceIndicatorMultiple" 
    android:paddingLeft="6dip" 
    android:paddingRight="6dip" 


    android:textColor= Color.Red  //please correct the syntax 
/> 

Đây là cùng một bố trí android.R.layout.simple_list_item_multiple_choice nhưng bây giờ bạn đang làm cùng trong bố trí của bạn với cùng một id để thực hiện các thay đổi trong đó.

+0

Tôi tạo một tệp xml mới và sao chép tệp này vào hoặc cái gì? –

+0

tạo một xml mới trong bố cục với bất kỳ tên nào của bạn, dán mã này vào xml đó và sử dụng xml này thay cho android.R.layout.simple_list_item_multiple_choice trong bộ điều hợp của bạn. Như định nghĩa trước ArrayAdapter sẽ tìm kiếm id "text1" trong get view và sẽ nhận được điều đó khi bạn có điều đó cũng trong xml của bạn. –

+0

Tôi có lỗi này ngay bây giờ: Lỗi: Các loại chuỗi không được phép (tại 'layout_width' có giá trị 'match_parent'). –

0

bạn có thể thử xem danh sách tùy chỉnh .. theo liên kết click here

0
<TextView 
     android:id="@+id/text_name" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" 
     android:text="Name" 
     android:textColor="@color/white" 
     android:textSize="11dp" 
/> 
4
android:textColor="@android:color/white" 
Các vấn đề liên quan