Android to TextView set a transparent background, rounded border

Source: Internet
Author: User
Tags set background

The first method: Create a new file under the Drawable folder to set the background style

Code:

Create a new Text_view_border.xml under the Drawable folder

[Java]View Plaincopy
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <shape xmlns:android="http://schemas.android.com/apk/res/android" >
  3. <solid android:color="#80858175"/>
  4. <stroke android:width="1dip" android:color= "#aea594"/>
  5. <corners android:topleftradius="2DP"
  6. android:toprightradius="2DP"
  7. android:bottomrightradius="2DP"
  8. android:bottomleftradius="2DP"/>
  9. </shape>


Called in the layout file

[Java]View Plaincopy
    1. <textview
    2. android:id="@+id/tv"
    3. Android:layout_width="Wrap_content"
    4. android:layout_height="Wrap_content"
    5. android:background="@drawable/text_view_border"/>

Called in the class file:

[Java]View Plaincopy
    1. Tv.setbackgroundresource (R.drawable.text_view_border);

Analysis:

Solid sets the fill color, and the color value begins with #80 to indicate transparency

Stroke set Border width, color value

Corners setting rounded corners

Second method: Set background with picture

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.