Skip to content Skip to sidebar Skip to footer

Changing A Divider With Setdivider In A Listactivity Without A Custom Listview?

I can't seem to get a customized divider, using a Drawable I've defined, to work when using a ListActivity and not creating a custom ListView. It almost seems like when the VM cre

Solution 1:

I figured it out. The issue had nothing to do with the ListActivity generating a ListView for me. It was in how I was defining the divider in Java code.

There are two ways that I see to define the divider (border between ListView rows) on a ListView that is automatically inflated from a ListActivity, if you want to define the color in XML:

Method 1:

In res/values/colors.xml, put the following:

<resources><colorname="sage">#cceebb</color></resources>

In your ListActivity-extending class, do this:

ListViewlv= getListView();
ColorDrawablesage=newColorDrawable(this.getResources().getColor(R.color.sage));
lv.setDivider(sage);
lv.setDividerHeight(1);

Method 2:

In res/values/colors.xml:

<resources><drawablename="sage">#cceebb</drawable></resources>

And in your class that extends ListActivity:

ListViewlv= getListView();
ColorDrawablesage=newColorDrawable(this.getResources().getColor(R.drawable.sage));
lv.setDivider(sage);
lv.setDividerHeight(1);

Solution 2:

To set divider in listview programatically:

These code put inside in your .java Class

ListViewlv= (ListView) findViewById(R.id.lv);
   lv.setDivider(getResources().getDrawable(R.drawable.drawable_divider));
   lv.setDividerHeight(1);

Creating Drawable: {res > drawable > drawable_divider.xml}

<?xml version="1.0" encoding="utf-8"?><shapexmlns:android="http://schemas.android.com/apk/res/android"android:shape="rectangle"><solidandroid:color="#ececec"></solid></shape>

Solution 3:

Try this code:

searchText.setBackgroundColor(getResources().getColor(R.color.wordColorBlack));
ListViewlv= getListView();
lv.setDivider(getResources().getDrawable(R.drawable.divider2));
lv.setDividerHeight(2);

Post a Comment for "Changing A Divider With Setdivider In A Listactivity Without A Custom Listview?"