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 access information about the default divider for ListView and use it for my form?
This is how it's done in some Android sources
<View
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?android:attr/listDivider" />
This will get the default list divider that matches your applications theme:
int[] attrs = { android.R.attr.listDivider };
TypedArray ta = getApplicationContext().obtainStyledAttributes(attrs);
//Get Drawable and use as needed
Drawable divider = ta.getDrawable(0);
//Clean Up
ta.recycle();
This is how I do it
<ImageView
android:layout_width="fill_parent"
android:layout_height="1dp"
android:scaleType="fitXY"
android:src="?android:attr/listDivider" />
To get default horizontal divider from code you could use:
final TypedArray array = getContext().getTheme().obtainStyledAttributes(
R.style.<some_theme>, new int[] {
android.R.attr.dividerHorizontal
});
final int defaultDivider = array.getResourceId(0, 0);
final Bitmap dividerBitmap = BitmapFactory.decodeResource(r, defaultDivider);
final BitmapDrawable divider = new BitmapDrawable(r, dividerBitmap);
Then, to also draw it yourself on a Canvas
in onDraw
:
divider.setBounds(X, Y, X + width, Y + height);
divider.draw(canvas);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With