Optimization of the prompt box: Custom Toast component (1) Toast component layout implementation, toast component

Source: Internet
Author: User

Optimization of the prompt box: Custom Toast component (1) Toast component layout implementation, toast component

Development steps:

  • Create a Toast layout resource file toast_customer.xml in layout under res.
  • Add the android: id attribute to the layout in the outermost layout component.
1 // toast_customer.xml 2 3 <? Xml version = "1.0" encoding = "UTF-8"?> 4 <LinearLayout xmlns: android = "http://schemas.android.com/apk/res/android" 5 android: id = "@ + id/toast_layout_root" // Add android: id attribute 6 android: layout_width = "match_parent" 7 android: layout_height = "match_parent" 8 android: orientation = "horizontal" 9 10 <TextView11 android: id = "@ + id/toastMessage" 12 android: layout_width = "wrap_content" 13 android: layout_height = "30dp" 14 android: gravity = "center_horizontal | center_vertical" 15 android: textSize = "13dp" 16 android: textColor = "#000000" 17/> 18 </LinearLayout>
  • Create a component style rule xml resource file under drawable under res
1 //toast_border_bg.xml2 3 <?xml version="1.0" encoding="utf-8"?>4 <shape xmlns:android="http://schemas.android.com/apk/res/android" >5     <corners android:radius="8dp"/>6     <solid android:color="#55FFFFFF"/>7     <stroke android:width="0.5dp" android:color="#FFFFFF"/>8 </shape>
  • Toast_customer.xml references the created style rule resource file
1 // toast_customer.xml 2 3 <? Xml version = "1.0" encoding = "UTF-8"?> 4 <LinearLayout xmlns: android = "http://schemas.android.com/apk/res/android" 5 android: id = "@ + id/toast_layout_root" 6 android: layout_width = "match_parent" 7 android: layout_height = "match_parent" 8 android: orientation = "horizontal" 9 android: background = "@ drawable/toast_border_bg"> // reference the created style rule resource file lifecycle 11 <TextView12 android: id = "@ + id/toastMessage" 13 android: layout_width = "wrap_content" 14 android: layout_height = "30dp" 15 android: gravity = "center_horizontal | center_vertical" 16 android: textSize = "22dp" 17 android: text = "test" 18 android: textColor = "#000000" 19/> 20 </LinearLayout>

Run:

 

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.