2015-08-03 47 views
-2

我試圖更改我的字體(顏色和大小)和我的ListView背面。我想用不在xml上的代碼行來改變它。我的列表視圖看起來像:xml: 請回答我的問題。 三江源如何更改列表視圖上的顏色和字體

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" > 

    <ListView 
     android:id="@+id/listview" 
     style="@style/styleName" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:dividerHeight="10dp" > 
    </ListView> 
</LinearLayout> 

代碼是:

package ir.Rubin.SecondTerm; 

import java.util.ArrayList; 
import java.util.List; 
import android.app.Activity; 
import android.graphics.Color; 
import android.os.Bundle; 
import android.widget.ArrayAdapter; 
import android.widget.ListView; 

public class ActivityListView extends Activity { 
    ListView mListView; 
    List<String> mList = new ArrayList<String>(); 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     // TODO Auto-generated method stub 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.layout_listview); 
     // findView 
     mListView = (ListView) findViewById(R.id.listview); 
     // for adding items 
     for (int i = 0; i < 200; i++) { 
      mList.add("Android Class" + i); 
     } 
     // Creating Data 
     ArrayAdapter<String> mAdapter = new ArrayAdapter<String>(this, 
       android.R.layout.simple_list_item_1, mList); 
     // Setting Adapter 
     mListView.setAdapter(mAdapter); 
    } 
} 
+0

換成你自己的這個android.R.layout.simple_list_item_1它將工作的佈局 – Amsheer

+0

@ m.asadi:請檢查so.too舊問題 –

+0

'mListView.setBackgrou ndColor(Color.BLUE);'並且爲了改變文本的顏色,你必須使用適配器類中的change方法,在那裏你把TEXTVIEW鏈接到佈局。 – Mohit

回答

-1
<ListView> 
    android:id="@+id/listview" 
    style="@style/styleName" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:dividerHeight="10dp" 
    android:textsize="#sp" 
    android:textColor="[hex color code here]" 
</ListView> 

這應該工作

相關問題