Android change color stroke (border) programmatically

前端 未结 1 1390
没有蜡笔的小新
没有蜡笔的小新 2021-01-18 10:45

I try change color \"stroke\", through \"GradientDrawable\" but not work.

also, I don\'t know how get id stroke, and change only stroke (I see google, all example a

1条回答
  •  孤城傲影
    2021-01-18 11:24

    Instead of this you may be use any layout and apply your xml as selector and for that layout you apply dynamic backgrounds via GradientDrawable.

    For example , main.xml

               
    

    Then your xml ,shapes.xml

                
                    
                        
                            
                            
                        
                    
                    
    

    And write following code in your activity.

        RelativeLayout  mainLayout= (RelativeLayout ) findViewById(R.id.mainLayout);
        GradientDrawable gd = new GradientDrawable();
        gd.setColor(Color.RED);
        gd.setCornerRadius(10);
        gd.setStroke(2, Color.WHITE);
        mainLayout.setBackgroundDrawable(gd);
    

    For more GradientDrawable use the link http://developer.android.com/reference/android/graphics/drawable/GradientDrawable.html

    Hopes this will help you.

    0 讨论(0)
提交回复
热议问题