Axelfran
Axelfran

Reputation: 1004

How to create a large blurred shadow behind a TextView?

I would like to create a quite large, soft shadow below my TextView. However I am not able to use a large enough shadow radius, as Android will crash if I set it to more than 25.0.

This is an example of the shadow I want to create

This is the largest shadow radius I'm able to create

The first of the images above is from our iOS app, and shows the shadow beneath the text as I want it. As you can see I'm not able to recreate this shadow effect on Android.

The XML style for the shadow effect is currently like this:

<style name="TextViewShadowEffectSoft">
    <item name="android:shadowColor">#DD000000</item>
    <item name="android:shadowDx">0.0</item>
    <item name="android:shadowDy">0.0</item>
    <item name="android:shadowRadius">25.0</item>
</style>

Which is inflated to the AutoResizeTextView (ancestor of TextView) at creation:

 AutoResizeTextView title = (AutoResizeTextView) getActivity().getLayoutInflater().inflate(R.layout.text_shadow_soft, null);

Where text_shadow_soft.xml is:

com.app.models.AutoResizeTextView
style="@style/TextViewShadowEffectSoft" />

My app has a minimum API of 19.

EDIT: Crash log when setting android:shadowRadius higher than 25.0:

05-12 13:16:20.590 10679-10781/com.app E/rsC++: RS CPP error: Blur radius out of 0-25 pixel bound
05-12 13:16:20.593 10679-10781/com.app E/rsC++: RS CPP error (masked by previous error): Allocation creation failed
05-12 13:16:20.593 10679-10781/com.app E/rsC++: RS CPP error (masked by previous error): Allocation creation failed
05-12 13:16:20.593 10679-10781/com.app E/rsC++: RS CPP error (masked by previous error): Blur radius out of 0-25 pixel bound

                                                      --------- beginning of crash
05-12 13:16:20.594 10679-10781/com.app A/libc: Fatal signal 11 (SIGSEGV), code 1, fault addr 0x28 in tid 10781 (RenderThread)

Appreciate all thoughts and input!

Upvotes: 5

Views: 2565

Answers (1)

Jiang YD
Jiang YD

Reputation: 3311

It seems some code related to your hardware limits it. So please use software rendering, add android:layerType="software" to your view.

Or in code use

myView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);

Documentation

Upvotes: 4

Related Questions