Style bottom Line in Android

后端 未结 14 2630
独厮守ぢ
独厮守ぢ 2020-11-28 17:53

I need to create an android shape so that only the bottom has stroke (a dashed line). When I try the following, the stroke bisects the shape right through the center. Does a

14条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-11-28 18:36

    use this xml change the color with your choice.

    
        
            
                
                    
    
                
            
            
            
                
                    
                
            
        
    
    

    In Case if you want programmatically

    public static Drawable getStorkLineDrawable(@ColorInt int colorStrok, int    iSize, int left, int top, int right, int bottom)
    
    {
        GradientDrawable gradientDrawable = new GradientDrawable();
        gradientDrawable.setShape(GradientDrawable.RECTANGLE);
        gradientDrawable.setStroke(iSize, colorStrok);
        LayerDrawable layerDrawable = new LayerDrawable(new Drawable[]{gradientDrawable});
        layerDrawable.setLayerInset(0, left, top, right, bottom);
        return layerDrawable;
    }
    

    call this method like

      Drawable yourLineDrawable=  getStorkLineDrawable(yourColor, iSize, -iSize, -iSize, -iSize, 0);
    

提交回复
热议问题