Android如何设置圆角按钮

1. res目录下的drawable目录下新建shape.xml文件

[html]  view plain  copy
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <shape xmlns:android="http://schemas.android.com/apk/res/android"  
  3.     android:shape="rectangle" >  
  4.   
  5.     <!-- 填充的颜色 -->  
  6.     <solid android:color="#FF065E8D" />  
  7.   
  8.     <!-- 设置按钮的四个角为弧形 -->  
  9.     <!-- android:radius 弧形的半径 -->  
  10.     <corners android:radius="15dip" />  
  11.   
  12.     <!-- padding:Button里面的文字与Button边界的间隔 -->  
  13.     <padding  
  14.         android:bottom="10dp"  
  15.         android:left="10dp"  
  16.         android:right="10dp"  
  17.         android:top="10dp" />  
  18. </shape>  

2.在布局文件中调用。

[html]  view plain  copy
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  3.     android:layout_width="fill_parent"  
  4.     android:layout_height="fill_parent"  
  5.     android:orientation="vertical" >  
  6.   
  7.     <Button  
  8.         android:id="@+id/roundButton"  
  9.         android:layout_width="wrap_content"  
  10.         android:layout_height="wrap_content"  
  11.         android:background="@drawable/shape"  
  12.         android:text="圆角按钮" />  
  13. </LinearLayout>  

nvisible:不显示,但保留所占的空间

visible:正常显示

gone:不显示,且不保留所占的空间

XML里:

android:visibility="visible"

代码里,如Button

btn.setVisibility(View.VISIBLE);


猜你喜欢

转载自blog.csdn.net/qq_41238313/article/details/78968128