您好,登錄后才能下訂單哦!
要給Spinner控件的列表項添加圓角邊框,可以通過自定義Adapter來實現(xiàn)。首先,創(chuàng)建一個自定義的Adapter類,繼承自ArrayAdapter,并重寫getView()方法來設(shè)置列表項的樣式。
在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設(shè)置給Spinner控件即可實現(xiàn)列表項的圓角邊框效果。
免責聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。