Android rounded border, gradient background TextView

Source: Internet
Author: User

Add a red border:

XML for TextView:

<?xml version= "1.0" encoding= "Utf-8"? ><linearlayout xmlns:android= "http://schemas.android.com/apk/res/ Android "    android:layout_width=" match_parent "    android:layout_height=" match_parent "    android:o rientation= "vertical"     android:paddingleft= "20DP"    android:paddingright= "20DP"    >        <!-- Specify background by Android:background--    <textview         android:layout_width= "match_parent"        android:layout_ height= "Wrap_content"        android:text= "text with border"        android:textsize= "24sp"        android:background= "@ Drawable/bg_border "        /></linearlayout>

Border xml: (new Folder drawable. Then create a new file under this folder Bg_border.xml)

<?xml version= "1.0" encoding= "Utf-8"? ><shape xmlns:android= "Http://schemas.android.com/apk/res/android" > <!--set red border--><stroke android:width= "2DP" android:color= "#f00"/></shape>

Effect


Gradient color:

<?xml version= "1.0" encoding= "Utf-8"? ><shape xmlns:android= "Http://schemas.android.com/apk/res/android" Android:shape= "Rectangle" > <!--Specify the radius of 4 fillets of rounded rectangles--<corners android:topleftradius= "5DP"     android: toprightradius= "5DP"     android:bottomleftradius= "5DP"     android:bottomrightradius= "5DP"     /> <!-- Specifies the width and color of the border line--<stroke android:width= "4DP" android:color= "#f0f"/>  <!--Specifies to use a gradient background color, using the sweep type of gradient, Color from red to green to blue--<gradient android:startcolor= "#f00"      android:centercolor= "#0f0"     android:endcolor= "# 00f "     android:angle=" android:centerx= "     0.5"     android:centery= "0.5"          /></shape>

Effect:


Description

(1) Shape node configuration is the form of graphics, mainly including square, round and so on

(2) Gradient node main configuration start color, end color and middle point color, coordinates, gradient effect (0,90,180 from left to right gradient, 270 from top to bottom gradient) default from left to right.

(3) The radius of the corners node is configured around the rounded corners.  


Android rounded border, gradient background TextView

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.