문제

Can a property such as First Color be set using code?

I would like to do something like this:

btnMyButton.drawable = "StatelistDrawable"
btnMyButton.drawable.EnabledDrawable = "GradientDrawable"
btnMyButton.drawable.EnabledDrawable.firstcolor = "255, 199, 199"
btnMyButton.drawable.EnabledDrawable.secondcolor = "255, 79, 79"
도움이 되었습니까?

해결책

If I understand your question correctly you need to create a GradientDrawable as below:

GradientDrawable gradient = new GradientDrawable( GradientDrawable.Orientation.TOP_BOTTOM, new int[] {0xFFRRGGBB,0xFFRRGGBB}); gd.setCornerRadius(0f);

Where RRGGBB is the color code in hex (eg 99CC00)

And then set the drawable as the background of your button:

btnMyButton.setBackgroundDrawable(gradient);

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top