Is there an easy way to add a border to the top and bottom of an Android View?

后端 未结 24 2865
盖世英雄少女心
盖世英雄少女心 2020-11-22 13:36

I have a TextView and I\'d like to add a black border along its top and bottom borders. I tried adding android:drawableTop and android:drawableBottom

24条回答
  •  暗喜
    暗喜 (楼主)
    2020-11-22 14:15

    In android 2.2 you could do the following.

    Create an xml drawable such as /res/drawable/textlines.xml and assign this as a TextView's background property.

    
    

    /res/drawable/textlines.xml

    
    
        
          
                
                
    
            
       
    
        
          
                
                
            
       
    
    
    

    The down side to this is that you have to specify an opaque background colour, as transparencies won't work. (At least i thought they did but i was mistaken). In the above example you can see that the solid colour of the first shape #FFffffdffffd is copied in the 2nd shapes stroke colour.

提交回复
热议问题