2
내가 (추악한 이미지에 대한 죄송)이 같은 드롭 다운 색상 선택기를 만들

:안드로이드 드롭 다운 색상 선택기

color dropdown picker

를 I 만하면 몇 가지 색상 (의 6 가정 해 봅시다) 그래서 돈 ' 완벽한 색상 선택기가 필요하다면 드롭 다운이 정상적으로 작동합니다.

Spinner 용 배열 어댑터를 확장하고 getDropDownViewgetView을 재정의해야한다는 것을 알고 있습니다.

테두리와 단색 배경색으로 사각형 상자를 만드는 방법은 잘 모르겠습니다.

drawable 안에 내 자신의 모양을 정의 할 수 있다는 것을 알고 있습니다. 어쨌든 런타임시 배경색을 설정해야하므로 뷰를 변경하고 올바른 배경색을 설정해야합니다.

이렇게하는 것이 가장 좋은 방법은 무엇입니까? 감사.

+1

(http://www.betaful.com/2012/01/programmatic-shapes-in-android/) –

+0

를 나는 당신의 answed를 사용 드롭 다운 요소에 대해서는 KEYSAN이 회 전자 텍스트 항목에 대해 대답합니다. 고마워. – Antonio

답변

5

배경색 만 원하는 경우이 예제처럼 사용할 수 있습니다.

public class CustomSpinnerAdapter<T extends BaseEntity> extends ArrayAdapter implements SpinnerAdapter {  

    private final List<T> objects; // android.graphics.Color list 

    public CustomSpinnerAdapter(Context context, List<T> objects) { 
     super(context, R.layout.yourLayout, objects); 
     this.context = context; 
     this.objects = objects; 

    } 

    @Override 
    public View getDropDownView(int position, View convertView, ViewGroup parent) { 
     super.getDropDownView(position, convertView, parent); 

     View rowView = convertView; 


     if (rowView == null) { 
      // Get a new instance of the row layout view 
      LayoutInflater inflater = this.activity.getLayoutInflater(); 
      rowView = inflater.inflate(R.layout.yourLayout, null); 

      rowView.setBackgroundColor(objects.get(position)); 

     } else { 
      rowView.setBackgroundColor(objects.get(position)); 
     } 


     return rowView; 
    } 

    @Override 
    public View getView(int position, View convertView, ViewGroup parent) { 
     View rowView = convertView; 


     if (rowView == null) { 
      // Get a new instance of the row layout view 
      LayoutInflater inflater = this.activity.getLayoutInflater(); 
      rowView = inflater.inflate(R.layout.yourLayout, null); 

      rowView.setBackgroundColor(objects.get(position)); 

     } else { 
      rowView.setBackgroundColor(objects.get(position)); 
     } 


     return rowView; 
    } 
} 
당신이 ... 동적 모양 당김을 만들 [여기]를보고 할 수 있습니다