android 设置Spinner文字标题颜色 字体大小样式

// 在初始化之前改变 Spinner文字标题颜色         mySpinner.xml 样式文件放在main.xml 同一目录

mySpinner.xml



ArrayAdapter adapter = new ArrayAdapter(this, R.layout.mySpinner.xml, curs);   //此处加上自己的样式

效果如下:

 

// 初始化完了后改变 Spinner文字标题颜色

private void setCursListener(String[] curs, int select, boolean monitor) {
        Spinner spinner = (Spinner)findViewById(R.id.spinner1);
        ArrayAdapter adapter = new ArrayAdapter(this, android.R.layout.simple_spinner_item, curs);
        adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        spinner.setAdapter(adapter);
        spinner.setSelection(select);
        if(monitor){
            spinner.setOnItemSelectedListener(new OnItemSelectedListener(){
                @Override
                public void onItemSelected(AdapterView parent, View view, int position, long id){
                    curyid = position;
                    //showPrice(position);
                     TextView tv = (TextView)view;
                    tv.setTextColor(getResources().getColor(R.color.white));    //设置颜色

                     tv.setTextSize(12.0f);    //设置大小

                     tv.setGravity(android.view.Gravity.CENTER_HORIZONTAL);   //设置居中
                }
                @Override
                public void onNothingSelected(AdapterView parent){}
            });
        }
    }


你可能感兴趣的:(ANDROID)