I've been trying to set a top and bottom border to a TextView, which rests inside a ConstraintLayout, which is sitting in a CardView:
<androidx.cardview.widget.CardView
android:id="@+id/ham_frame"
android:layout_width="244dp"
android:layout_height="100dp"
android:layout_marginTop="24dp"
android:layout_marginEnd="24dp"
app:cardBackgroundColor="?attr/background"
app:cardCornerRadius="4dp"
app:cardElevation="3dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent">
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/ham_frame_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/textView6"
android:layout_width="wrap_content"
android:layout_height="32dp"
android:background="@drawable/border_top_bottom"
android:text="TextView"
android:textAlignment="center"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.cardview.widget.CardView>
The layer-list:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:top="-2dp" android:left="-2dp" android:right="-2dp">
<shape android:shape="rectangle">
<stroke android:width="1dp" android:color="?attr/colorSeperator" />
<solid android:color="#00000000" />
</shape>
</item>
<item android:bottom="-2dp" android:left="-2dp" android:right="-2dp">
<shape android:shape="rectangle">
<stroke android:width="1dp" android:color="?attr/colorSeperator" />
<solid android:color="#00000000" />
</shape>
</item>
</layer-list>
Now, I have gone through the questions asked about how to do that earlier, and followed multiple variations of the layer-list drawable to set as the background of the TextView, but that is simply not working for me (no borders are rendered in both a device and the editor).
Instead of that, setting the drawable as foreground just works, but the issue with that is it seems to be unsupported below API 23 (which is not acceptable).
Multiple answers here: Is there an easy way to add a border to the top and bottom of an Android View? seem to instruct to set the drawable as background, and there doesn't seem to be anyone facing the same issue - what could I be doing wrong?
EDIT: ?attr/colorSeperator
is correctly set to #764AFF1A
Double-checked, neither the editor (API 26-29) nor my LG device (G7+ Pie) render the borders.
On device, with drawable set as background:
With drawable set as foreground:
Please note the shadow-esque appearance at the top and left edges are of the container, not the TextView (which is supposed to display a slight purple-ish border).