I have a RelativeLayout
container with a blue background color. Inside of it I have a TextView element, but for some reason the background is rendered on top of my text and not behind it.
Here’s my code:
<RelativeLayout
android:id="@+id/my_widget"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="130dp"
android:layout_height="130dp"
android:background="@drawable/layout_bg">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="center_horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="🥳"
android:textSize="80dp"
/>
</LinearLayout>
</RelativeLayout>
My Bg
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#00aaff"/>
<corners android:radius="15dp"/>
<padding android:left="0dp" android:top="0dp" android:right="0dp" android:bottom="0dp" />
</shape>
Result:
3
Answers
Option 1: Use FrameLayout instead of Relative layout.
Option 2: Try Elevation in your child layout.
Set any color to TextView like:
This is due to the default text foreground color of Android .
Set any TextColor to the textview.