How to change color of drawable shapes in android

前端 未结 6 909
时光取名叫无心
时光取名叫无心 2020-12-09 15:09

I am developing small android application in which I set drawable resource as background for linear layout. Now what I want to do change background color of linear layout dy

6条回答
  •  臣服心动
    2020-12-09 16:13

    Also possible way is to use:

    val layerDrawable : LayerDrawable = imageView.background as LayerDrawable
    val bgShape = layerDrawable.findDrawableByLayerId(R.id.shape_id) as GradientDrawable
    bgShape.setColor(ContextCompat.getColor(context, R.color.colorPrimary))   
    

    with example (drawable/circle.xml):

    
    
    
        
            
            
            
        
    
    
    

    and ImageView:

    
    

提交回复
热议问题