1

I wanted to add a shadow to a TextView, but on my phone the shadow color is always white, although it is supposed to be gray. In the layout validator of Android Studio it looks the way it is supposed to.

Here is my xml code:

    <TextView
        android:id="@+id/tvName"
        android:layout_width="wrap_content"
        android:layout_height="46dp"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="5dp"
        android:fontFamily="@font/patrick_hand"
        android:gravity="bottom|center_horizontal"
        android:shadowColor="@color/gray_1"
        android:shadowDx="7"
        android:shadowDy="7"
        android:shadowRadius="5"
        android:text="Name"
        android:textAlignment="gravity"
        android:textColor="@color/white"
        android:textSize="35sp" />

I also tried to set the shadow effect programmatically, which also didn't work.

tvName.setShadowLayer(5, 7, 7, R.color.gray_1);

It has something to do with the dark/light themes, if I turn off darkmode, the shadow is black. But I have the same colors for dark/light theme, so I really don't know what's going on.

1 Answers1

0

to set shadow you can try,

make new xml and use below code,

    <item android:drawable="@android:drawable/dialog_holo_light_frame"/>

    <item>
        <shape android:shape="rectangle">
            <corners android:radius="1dp" />
            <solid android:color="@color/gray_200" />
        </shape>
    </item>

</layer-list>

then, call below code, android:background="@drawable/myrect" .

MAYUR SANCHETI
  • 420
  • 3
  • 10