Add a shadow effect to TextView or Button text in android

Source: Internet
Author: User

1. There is a method for adding text shadow TextView to the code/*** Gives the text a shadow of the specified radius and color, the specified * distance from its normal position. ** @ attr ref android. r. styleable # TextView_shadowColor * @ attr ref android. r. styleable # TextView_shadowDx * @ attr ref android. r. styleable # TextView_shadowDy * @ attr ref android. r. styleable # TextView_shadowRadius */public void setShadowLayer (float radius, float d X, float dy, int color) {mTextPaint. setShadowLayer (radius, dx, dy, color); mShadowRadius = radius; mShadowDx = dx; mShadowDy = dy; invalidate ();} mTextView. setShadowLayer (10F, 11F, 5F, Color. YELLOW); the first parameter is fuzzy, the greater the fuzzy. The second parameter is the x horizontal distance from the shadow text. The third parameter is the Y horizontal distance from the shadow text. The fourth parameter is the shadow color. (If the Blur is 0, the shadow effect is invisible.) The Button inherits TextView, so the Button can also use setShadowLayer (float radius, float dx, float dy, int color) in the code) method 2 Add text shadow to the configuration file <TextView android: id = "@ + id/name" android: layout_width = "wrap_content" android: layout_height = "wrap_content" android: layout_above = "@ + id/person_popularvalue" android: layout_alignParentLeft = "true" android: layout_marginBottom = "5.0dip" android: layout_marginLeft = "10.0dip" android: ShadowColor = "@ color/black" android: shadowDx = "0" android: shadowDy = "1" android: shadowRadius = "1" android: textColor = "@ color/white" android: textSize = "14sp"> </TextView> android: shadowColor shadow color android: horizontal offset of shadowDx shadow android: shadowDy shadow vertical offset android: shadowRadius shadow range Note: add the text shadow effect of the Button that does not see the shadowRadius when android: shadowRadius = 0 is the same as the above.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.