如何在Android Studio中使用微调器以编程方式更改textView中的背景颜色

时间:2019-01-02 08:23:54

标签: android

如何在Android Studio中使用微调器以编程方式更改textView中的背景颜色?

public void onItemSelected(AdapterView<?> parent, View v, int position, long id) {
    ContactHolder contactHolder= new ContactHolder();
    switch (position) {
        case 0:
            Toast.makeText(getContext(),"Bilal",Toast.LENGTH_SHORT).show();
            contactHolder.textview.setBackgroundColor(getResources().getColor(color.white));
            break;
        case 1:
            Toast.makeText(getContext(),"Asad",Toast.LENGTH_SHORT).show();
            break;
        case 2:
            Toast.makeText(getContext(),"Sir Usman",Toast.LENGTH_SHORT).show();
            break;
        case 3:
            Toast.makeText(getContext(),"Hamad",Toast.LENGTH_SHORT).show();
            break;
        case 4:
            Toast.makeText(getContext(),"Saad",Toast.LENGTH_SHORT).show();
            break;
        case 5:
            Toast.makeText(getContext(),"Shoaib",Toast.LENGTH_SHORT).show();
            break;
    }
}

0 个答案:

没有答案