Skip to content
Merged
16 changes: 11 additions & 5 deletions android/src/toga_android/widgets/divider.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
from android.graphics import Color
from android.view import View
from android.widget import LinearLayout
from travertino.size import at_least

from .base import Widget

try:
from com.google.android.material.divider import MaterialDivider
except ImportError: # pragma: no cover
# If you've got an older project that doesn't include the Material library,
# this import will fail. We can't validate that in CI, so it's marked no cover
MaterialDivider = None


class Divider(Widget):
def create(self):
self.native = View(self._native_activity)
self.require_material(MaterialDivider, "MaterialDivider")

# Background color needs to be set or else divider will not be visible.
self.native.setBackgroundColor(Color.LTGRAY)
# MaterialDivider draws a line that fills the whole view, so a view that's
# narrow and tall gives a vertical divider.
self.native = MaterialDivider(self._native_activity)

self._direction = self.interface.HORIZONTAL

Expand Down
2 changes: 1 addition & 1 deletion android/tests_backend/widgets/divider.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@


class DividerProbe(SimpleProbe):
native_class = jclass("android.view.View")
native_class = jclass("com.google.android.material.divider.MaterialDivider")
1 change: 1 addition & 0 deletions changes/4922.feature.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
On Android, dividers now use the Material Design style.
Loading