您好,登錄后才能下訂單哦!
要給Spinner控件的列表項添加圓角邊框,可以通過自定義Adapter來實現。首先,創建一個自定義的Adapter類,繼承自ArrayAdapter,并重寫getView()方法來設置列表項的樣式。
在getView()方法中,可以使用ShapeDrawable和GradientDrawable來繪制圓角邊框。具體步驟如下:
ShapeDrawable shapeDrawable = new ShapeDrawable(new RoundRectShape(new float[]{10, 10, 10, 10, 10, 10, 10, 10}, null, null));
GradientDrawable gd = new GradientDrawable();
gd.setColor(Color.WHITE);
gd.setStroke(2, Color.GRAY);
gd.setShape(GradientDrawable.RECTANGLE);
gd.setCornerRadii(new float[]{10, 10, 10, 10, 10, 10, 10, 10});
gd.setCornerRadii(new float[]{10, 10, 10, 10, 10, 10, 10, 10});
shapeDrawable.setPadding(5, 5, 5, 5);
shapeDrawable.getPaint().setColor(Color.WHITE);
shapeDrawable.getPaint().setStyle(Paint.Style.STROKE);
shapeDrawable.getPaint().setStrokeWidth(2);
shapeDrawable.setIntrinsicWidth(50);
shapeDrawable.setIntrinsicHeight(50);
gd.setShape(GradientDrawable.RECTANGLE);
gd.setCornerRadius(10);
gd.setStroke(2, Color.GRAY);
gd.setShape(GradientDrawable.RECTANGLE);
shapeDrawable.getPaint().setColor(Color.WHITE);
shapeDrawable.getPaint().setStyle(Paint.Style.STROKE);
shapeDrawable.getPaint().setStrokeWidth(2);
shapeDrawable.getPaint().setStrokeWidth(2);
shapeDrawable.getPaint().setStyle(Paint.Style.STROKE);
shapeDrawable.getPaint().setColor(Color.GRAY);
shapeDrawable.getPaint().setStrokeWidth(2);
shapeDrawable.setShape(new RoundRectShape(new float[]{10, 10, 10, 10, 10, 10, 10, 10}, null, null));
view.setBackground(shapeDrawable);
最后,將自定義的Adapter設置給Spinner控件即可實現列表項的圓角邊框效果。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。