Android height does not show shadows

I want to create a login screen by placing a linear layout containing logging items in the middle of the screen with some shadows. Even though I set the height and padding for this linear layout, I still don't get any shadows. look? Here is my layout file:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent">

    <LinearLayout
        android:orientation="vertical"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:gravity="center|center_vertical|center_horizontal">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textAppearance="?android:attr/textAppearanceLarge"
            android:text="Willkommen Sie!"
            android:id="@+id/textView2"
            android:textColor="@color/primary"
            android:textIsSelectable="false"
            android:textSize="90dp"
            android:textStyle="bold" />

    </LinearLayout>

    <LinearLayout
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:gravity="center"
        android:weightSum="1"
        android:clipChildren="false"
        android:focusable="true" android:focusableInTouchMode="true">

        <LinearLayout
            android:orientation="vertical"
            android:layout_width="385dp"
            android:layout_height="wrap_content"
            android:background="@layout/loginborder"
            android:layout_weight="0.30"
            android:gravity="center"
            android:padding="8dp"
            android:elevation="8dp">

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Name"
                android:id="@+id/textView3"
                android:textSize="32dp"
                android:textIsSelectable="false" />

            <EditText
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:inputType="textPersonName"
                android:ems="10"
                android:id="@+id/editText2" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Kennwort"
                android:id="@+id/textView4"
                android:textSize="32dp" />

            <EditText
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:inputType="textPassword"
                android:ems="10"
                android:id="@+id/editText" />

            <Button
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Login"
                android:background="@drawable/button_orange"
                android:textColor="#ffffff"
                android:id="@+id/login"
                android:layout_marginTop="20dp" />
        </LinearLayout>
    </LinearLayout>

</LinearLayout>

      

+3


source to share


2 answers


I don't believe you can get the elevation above the text to create shadows for the letters. The closest you can do is create a kind of floating mark by setting an opaque background and height directly to the text view; eg,

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Name"
    android:id="@+id/textView3"
    android:textSize="32dp"
    android:background="#FFFFFFFF"
    android:elevation="8dp"
    android:textIsSelectable="false" />

      

or, to add some dimension, you can use an old CBT (Computer Learned) trick to compensate for contrasting text behind body text (which should be opaque):



<FrameLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="1.5sp"
        android:layout_marginTop="1.5sp"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:text="Willkommen Sie!"
        android:id="@+id/textView2shadow"
        android:textColor="#33000000"
        android:textIsSelectable="false"
        android:textSize="90dp"
        android:textStyle="bold" />
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:text="Willkommen Sie!"
        android:id="@+id/textView2"
        android:textColor="?colorPrimary"
        android:textIsSelectable="false"
        android:textSize="90dp"
        android:textStyle="bold" />
</FrameLayout>

      

enter image description here

+1


source


Android: background = "@ layout / loginborder"

make sure your "logborder" background does not contain opacity (alpha)

android:color="#aaffffff"

      



it should be

android:color="#ffffff"

      

+1


source







All Articles