更改文本颜色微调的项目中解析后到来 [英] Change Text color Of spinner items coming after parsing

查看:162
本文介绍了更改文本颜色微调的项目中解析后到来的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新的android..so需要一些帮助.. 我有一个XML页面,白色background..in它有一个spinner..the值填充后parsing..but问题微调是,当我点击该微调的文本颜色也是白色的,背景微调也是white..therefore文字不visible..i希望出现这种微调的所有项目shiuld是黑色color..i已经得到了一些线程,但是通过唯一入选的项目呈现出黑色... 需要UR HLP ...日Thnx提前..

I am new in android..so need a some help.. I have a xml page with white background..in it there is a spinner..the values are populating in that spinner after parsing..but problem is that when i click on that spinner the text color is also white and the background of that spinner is also white..therefore the text are not visible..i want that all the items of the spinner shiuld be of black color..i have got some threads but through that only selected item is showing black colour... need ur hlp...thnx in advance..

推荐答案

您必须实施微调的onItemSelected。 像这样的:

You must have implemented onItemSelected of spinner. Like this:

public class YourActivity_Name extends Activity implements
    AdapterView.OnItemSelectedListener {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.main);

    spinner = (Spinner) findViewById(R.id.Spinner1);

    spinner.setOnItemSelectedListener(this);

    }

public void onItemSelected(AdapterView<?> parent, View view, int pos,
        long id) {


     ((TextView) parent.getChildAt(0)).setTextColor(Color.BLUE);

}

@Override
public void onNothingSelected(AdapterView<?> arg0) {
    // TODO Auto-generated method stub
}


}

更新:

在微调之后,你必须设置项很喜欢这样的:

Then you must have set items in spinner likes this:

ArrayAdapter<CharSequence> adapter = new ArrayAdapter<CharSequence>(
                context, android.R.layout.simple_spinner_item,
                array_spinner);
        adapter.setDropDownViewResource(R.layout.simple_selectable_list_item);
        spinner.setAdapter(adapter);

simple_selectable_list_item.xml

<?xml version="1.0" encoding="utf-8"?>
<CheckedTextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/textView1"
android:layout_width="match_parent"
android:layout_height="?android:attr/listPreferredItemHeight"
android:textAppearance="?android:attr/textAppearanceListItem"
android:gravity="center_vertical"
android:background="?android:attr/listChoiceBackgroundIndicator"
android:paddingLeft="8dip"
android:textColor="#ff0000"
android:paddingRight="8dip"

/>

这篇关于更改文本颜色微调的项目中解析后到来的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆