在做控件时对外观有要求,比如做成圆角的textview,可以通过shape作为背景。
        在drawable文件夹下New一个资源文件,然后root elements 为shape。
        定义shape 如下格式:
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android"> <stroke android:width="0.2dp" android:color="#fff222"/> <solid android:color="#ffffff"/> <corners android:radius="10dp"/> </shape>
最后在应用场景中添加background就ok了。
        
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:orientation="vertical" android:layout_height="match_parent" tools:context=".MainActivity"> <TextView android:id="@+id/tv_test" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Hello World!" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintRight_toRightOf="parent" app:layout_constraintTop_toTopOf="parent" /> <Button android:text="changed text" android:id="@+id/bt_changed" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <Button android:text="intent to next" android:id="@+id/bt_intent" android:layout_width="wrap_content" android:layout_height="wrap_content" /> </LinearLayout>
原样,然后添加background:
        
        
        更详细的信息可以参考:Android XML shape 标签使用详解
 
                   
                   
                   
                   
                             
       
           
                 
                 
                 
                 
                 
                
               
                 
                 
                 
                 
                
               
                 
                 扫一扫
扫一扫
                     
              
             
                   1323
					1323
					
 被折叠的  条评论
		 为什么被折叠?
被折叠的  条评论
		 为什么被折叠?
		 
		  到【灌水乐园】发言
到【灌水乐园】发言                                
		 
		 
    
   
    
   
             
            


 
            