Applying shadows to android layouts without using a 9-patch on
android 4.3 and below! (4.4 changed toast design)
Using a 9-patch is (sometimes) too much of a pain in the buttocks, when all you want is just a simple shadow, CSS has it, so why doesn't android??? Grrrrr...!
I found a hack.
While working on
Mr.Query, I was looking for a built-in android icon because I was too
lazy to design a new one.
Then, I stumbled upon:
android:background="@android:drawable/toast_frame"
android:background="@android:drawable/dialog_frame"
I tried it on a few different layouts and buttons, and it's not bad!
Here are a few examples:
<TextView
android:layout_width="fill_parent"
android:text="I am a simple textview with a shadow"
android:layout_height="wrap_content"
android:textSize="18sp"
android:padding="16dp"
android:textColor="#fff"
android:background="@android:drawable/toast_frame"
/>
<LinearLayout
android:layout_height="64dp"
android:layout_width="fill_parent"
android:gravity="center"
android:background="@android:drawable/toast_frame"
android:padding="4dp"
>
<Button
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="Button shadow"
android:background="#33b5e5"
android:textSize="24sp"
android:textStyle="bold"
android:textColor="#fff"
android:layout_gravity="center|bottom"
/>
</LinearLayout>
<LinearLayout
android:layout_height="64dp"
android:layout_width="fill_parent"
android:gravity="center"
android:background="@android:drawable/toast_frame"
android:padding="4dp"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="color textView with LinearLayout shadow"
android:background="#f2eee8"
android:textSize="18sp"
android:padding="4dp"
android:textColor="#111"
android:layout_gravity="center|bottom"
/>
</LinearLayout>
Made with hilite