猿问

如何在ListView上更改颜色和字体

我正在尝试更改字体(颜色和大小)以及ListView的背景。我想用不在xml上的代码行来更改它。我的列表视图如下:xml:


 <?xml version="1.0" encoding="utf-8"?>

<TextView xmlns:android="http://schemas.android.com/apk/res/android"

android:layout_width="fill_parent"

android:layout_height="fill_parent"

android:padding="10dp"

android:textSize="18sp" android:text="@string/hello">

</TextView>

我的代码是


public class NewsActivity  extends ListActivity {

/** Called when the activity is first created. */

@Override

public void onCreate(Bundle savedInstanceState) {

      super.onCreate(savedInstanceState);


 // ArrayAdapter listItemAdapter = new ArrayAdapter( this,android.R.layout.simple_list_item_1, v_itemList );


      setListAdapter(new ArrayAdapter<String>(this, R.layout.list_item,ynetList));


      View v=getListView() ;


      ListView lv = getListView();

接下来是什么?请根据我的代码给我一个例子


回首忆惘然
浏览 719回答 3
3回答

慕容3067478

更好的是,您无需为列表单元格视图创建单独的android xml布局。如果列表仅包含textview,则可以只使用“ android.R.layout.simple_list_item_1”。private class ExampleAdapter extends ArrayAdapter<String>{&nbsp; &nbsp; public ExampleAdapter(Context context, int textViewResourceId, String[] objects) {&nbsp; &nbsp; &nbsp; &nbsp; super(context, textViewResourceId, objects);&nbsp; &nbsp; }&nbsp; &nbsp; @Override&nbsp; &nbsp; public View getView(int position, View convertView, ViewGroup parent) {&nbsp; &nbsp; &nbsp; &nbsp; View view =&nbsp; super.getView(position, convertView, parent);&nbsp; &nbsp; &nbsp; &nbsp; TextView tv = (TextView) view.findViewById(android.R.id.text1);&nbsp; &nbsp; &nbsp; &nbsp; tv.setTextColor(0);&nbsp; &nbsp; &nbsp; &nbsp; return view;&nbsp; &nbsp; }
随时随地看视频慕课网APP

相关分类

Android
我要回答