Add a shadow effect to TextView or button text in Android

Source: Internet
Author: User

1 adding text shadows to your code

TextView has a method/**     * Gives The text a shadow of the specified radius and color, the specified  &nbs P  * 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 dx, float dy, int color) {        mtextpaint.setshadowlayer (radius, dx, dy, color);     &NB Sp   Mshadowradius = radius;        MSHADOWDX = dx;        Mshadowdy = dy;          invalidate ();   }mtextview.setshadowlayer (10F, 11f,5f, Color.yellow); The first parameter is a blur, and the larger the more blurred. The second parameter is the x transverse distance of the shadow leaving the text. The third parameter is the Y-lateral distance of the shadow from the text. The fourth parameter is a shadow color. (If the blur level is 0, the shadow effect is not visible.)The button is inherited TextView, so the button can also use Setshadowlayer (float radius, float dx, float dy, int color) method 2 in the code to add text shadows 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"           and nbsp Android:layout_alignparentleft= "true"             android:layout_marginbottom= "5.0dip"             android:layout_marginleft= "10.0dip"             and Roid:shadowcolor= "@color/black"             android:shadowdx= "0"             android:shadowdy= "1"             android:shadowradius= "1"             android:textcolor= "@color/wHite "            android:textsize=" 14SP "> </textview>android:shadowcolor The shadow's color android:shadowdx the horizontal offset of the shadow android:shadowdy the vertical offset of the shadow Android:shadowradius the extent of the shadow that needs attention: will Android:shadowradius=0 When you do not see the shadow of the button's text shadow effect is added as above.

Add a shadow effect to TextView or button text in Android

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.