How to change the text color of dropdown in an AutoCompleteTextView?

前端 未结 4 1878
难免孤独
难免孤独 2021-01-05 12:32

How can I change the text color in dropdown menu of an AutoCompleteTextView? Or how can I change the background color of a dropdown, by default dropdown\'s back

4条回答
  •  甜味超标
    2021-01-05 13:14

    you need to create custom adapter class for this, then you can set textview to this like.

    autoAdapter = new AutoAdapter(this, R.layout.autocompletelistview_test1,
                edittext);    
    

    Here is autocompletelistview_test1

    
    
    
    

    use following code to change background color of dropdown like

     autocomplete.setDropDownBackgroundResource(R.color.autocompletet_background_color);  
    

    and you can set value like this in string.xml

       #EFEFEF    
    

    If you want to change text color of dropdown item then do like following.

    in Adapter class.

     @Override
    public View getView(int position, View v, ViewGroup parent)
    {
        View mView = v ;
        if(mView == null){
            LayoutInflater vi = (LayoutInflater)appContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            mView = vi.inflate(id, null);
        }
        TextView text = (TextView) mView.findViewById(R.id.textview);        
        if(getItem(position) != null )
        {
            text.setTypeface(faceBold);
            if(getItem(position).equals("check some condition if you want. "))
            {
                text.setTextColor(Color.parseColor("#999999"));
                text.setText("set some text");               
            }           
            else
            {
                text.setTextColor(Color.parseColor("#cc3333"));
                    text.setText(getItem(position));
            }           
        }
        return mView;
    }    
    

    Let me know if you have any question.

提交回复
热议问题