Modify color Android selected Dropdown item

后端 未结 1 2062
终归单人心
终归单人心 2021-01-24 05:22

How can I modify the text color of the selected item on a Spinner in an Android Honeycomb application?

EDIT: I have a Spinner layout which i\'m inflating. Is it possible

1条回答
  •  萌比男神i
    2021-01-24 05:59

    I used this code for ListView adaper:

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
    
            View rowView;
            EntSaleDocumentDetails entSaleDocumentDetails = getItem(position);
    
            if (convertView == null) {
                LayoutInflater inflator = (LayoutInflater) getContext()
                        .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                rowView = inflator.inflate(R.layout.myLayout,
                        null);
            } else {
                rowView = (View) convertView;
            }
    
    
            TextView myTv= (TextView) rowView
                    .findViewById(R.id.tvCode);
    
            myTv.setTextSize(16);
    
            //....
    
            // set selected item
            LinearLayout ActiveItem = (LinearLayout) rowView;
            if (position == selectedItem)
            {
                ActiveItem
                        .setBackgroundResource(R.drawable.background_dark_blue);
            }
            else
            {
                ActiveItem
                        .setBackgroundResource(R.drawable.border02);
            }
            //....
    }
    
    public void setSelectedItem(int position) {
            selectedItem = position;
        }
    

    your custom layout:

    
    
    
        
    
            
            
    
            
        
    
        
    
            
    
            
    
                
    
                    
    
                    
    
                    
    
                    
                
    
                
    
                    
    
                    
    
                    
    
                    
                
            
        
    
    
    

    and in activity:

    @Override
        protected void onListItemClick(ListView parent, View view, int position,
                long id) {
            super.onListItemClick(parent, view, position, id);
            adapter.setSelectedItem(position);
            myListView.invalidateViews();
        }
    

    0 讨论(0)
提交回复
热议问题