我有一个包含列表视图的应用程序,我希望列表视图的第一行是蓝色的。我从数组 xml 中做了列表视图,这里是代码和 XML:JAVA:
public class MainActivity extends Activity implements OnItemClickListener {
ListView list;
ArrayAdapter<String> adaptr;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
list = (ListView) findViewById(R.id.listView1);
adaptr = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1
, getResources().getStringArray(R.array.list_view));
list.setAdapter(adaptr);
list.setOnItemClickListener(this);
list.setFastScrollEnabled(true);
}
public void onItemClick(AdapterView<?> adapterView, View view, int position, long id) {
Dialog dialog1 = new Dialog(this, R.style.PauseDialog);
dialog1.setContentView(R.layout.dialog1);
TextView text = (TextView) dialog1.findViewById(R.id.tv1);
dialog1.setTitle(R.string.Title);
if(position == 1) {
text.setText("First Dialog");
dialog1.show();
}
if(position == 2) {
text.setText("Second Dialog");
dialog1.show();
return;
}
if(position == 3) {
text.setText("Third Dialog");
dialog1.show();
return;
}
}
这是 XML:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<array name="list_view">
<item>All Rights Saved to XXX</item>
<item>Line 1</item>
<item>Line 2</item>
<item>Line 3</item>
</array>
</resources>
我想要第一个项目(“All Rghits ....”)将是蓝色(颜色)(另一个将是常规(黑色))