强大的SHAPE资源


shape资源可以定义形状、渐变、边距、边框、圆角(你越来越像一头猪了——“形渐变变圆” )
今使用shape资源实现一个圆角矩形风格的TextView 

定义shape资源:



   
    
    
android:bottom="7dp"  android:left="7dp"  android:right="7dp"  />
    
   
    
 

在布局中使用shape:
android:id="@+id/tv_shape"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/shape"
android:text="what a shape!"/> 

在代码中动态使用:
Drawable shape=getResources().getDrawable(R.drawable.shape); 
TextView tv=findViewById(R.id.tv_shape) ;
tv.setBackground(shape); 

你可能感兴趣的:(Android基础)