1. 程式人生 > >GradientDrawable 可以用來通過程式方式給控制元件設定背景如圓角,邊框等

GradientDrawable 可以用來通過程式方式給控制元件設定背景如圓角,邊框等

@SuppressLint("NewApi")
public void setPopupStyle(final int backgroundColor, final int borderColor, final int borderWidthDP, float cornerRadiusDP, final int textColor) {

    final GradientDrawable popupbackground = new GradientDrawable();
popupbackground.setCornerRadius(cornerRadiusDP * density);
popupbackground.setStroke((int
) (borderWidthDP * density), borderColor); popupbackground.setColor(backgroundColor); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) scrollIndicatorTextView.setBackgroundDrawable(popupbackground); else scrollIndicatorTextView.setBackground(popupbackground); scrollIndicatorTextView
.setTextColor(textColor); }