星空网 > 软件开发 > 操作系统

提示框的优化之自定义Toast组件之(一)Toast组件的布局实现

开发步骤: 

  • 在res下layout下创建一个Toast的布局资源文件toast_customer.
  • 在最外层布局组件中为该布局添加android:id属性 
 1 //toast_customer. 2  3 <??> 4 <LinearLayout ="http://schemas.android.com/apk/res/android" 5   android:id="@+id/toast_layout_root" //在最外层布局组件中为该布局添加android:id属性 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>

  • 在res下drawable下创建一个组件样式规则
1 //toast_border_bg.2 3 <??>4 <shape ="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.
 1 //toast_customer. 2  3 <??> 4 <LinearLayout ="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"> //引用创建好的样式规则资源文件toast_border_bg.10 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="测试"18     android:textColor="#000000"19     />20 </LinearLayout>

运行:

提示框的优化之自定义Toast组件之(一)Toast组件的布局实现images/loading.gif' data-original="http://images2015.cnblogs.com/blog/859700/201512/859700-20151231090012870-719656325.jpg" />

 




原标题:提示框的优化之自定义Toast组件之(一)Toast组件的布局实现

关键词:

*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。
相关文章
我的浏览记录
最新相关资讯
海外公司注册 | 跨境电商服务平台 | 深圳旅行社 | 东南亚物流