I am trying to add a top border to a LinearLayout with a transparent background.
The result should be like the following image, where the border is the top border of the "Jp Project" LinearLayout. The background color comes from a FrameLayout who is used as container.
This is the linear layout XML:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/menuItem"
android:layout_width="match_parent"
android:layout_height="50dp"
android:orientation="horizontal">
<ImageView
android:id="@+id/icon"
android:layout_width="45dp"
android:layout_height="45dp"
android:src="@drawable/notification_action"
android:padding="10dp"/>
<TextView
android:id="@+id/menuItemName"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center_vertical"
android:textSize="19sp"
android:textColor="@color/white"/>
<TextView android:id="@+id/counter"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center_vertical"
android:textAppearance="@android:style/TextAppearance.Medium"
android:textColor="@color/counter_text_color"
android:background="@drawable/counter_bg"/>
</LinearLayout>
This is the style code I am using at the moment:
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="line">
<stroke
android:width="2dp"
android:color="@color/base_app_color" />
<solid android:color="@android:color/transparent"/>
</shape>
Which draws:

Have you got any way to fix it just using styles?
Set as your LinearLayout background the drawable with this code:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:left="-2dp" android:bottom="-2dp" android:right="-2dp">
<shape android:shape="rectangle">
<stroke android:width="2dp" android:color="@color/borderColor" />
<solid android:color="@color/backgroundColor" />
</shape>
</item>
</layer-list>
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