Skip to content Skip to sidebar Skip to footer

How Can I Get The Default Divider?

I want to make a form and put a divider between each form element, and I want the divider to have to same style as what is default for the ListView on the platform. Can I somehow a

Solution 1:

This is how it's done in some Android sources

<Viewandroid:layout_width="match_parent"android:layout_height="wrap_content"android:background="?android:attr/listDivider" />

Solution 2:

This will get the default list divider that matches your applications theme:

int[] attrs = { android.R.attr.listDivider };
TypedArrayta= getApplicationContext().obtainStyledAttributes(attrs);
//Get Drawable and use as neededDrawabledivider= ta.getDrawable(0);
//Clean Up
ta.recycle();

Solution 3:

This is how I do it

<ImageViewandroid:layout_width="fill_parent"android:layout_height="1dp"android:scaleType="fitXY"android:src="?android:attr/listDivider" />

Solution 4:

To get default horizontal divider from code you could use:

finalTypedArrayarray= getContext().getTheme().obtainStyledAttributes(
            R.style.<some_theme>, newint[] {
                android.R.attr.dividerHorizontal
            });
    finalintdefaultDivider= array.getResourceId(0, 0);
    finalBitmapdividerBitmap= BitmapFactory.decodeResource(r, defaultDivider);
    finalBitmapDrawabledivider=newBitmapDrawable(r, dividerBitmap);

Then, to also draw it yourself on a Canvas in onDraw:

divider.setBounds(X, Y, X + width, Y + height);
divider.draw(canvas);

Post a Comment for "How Can I Get The Default Divider?"