第二次加载片段时,TextView SetColor无法正常工作
我正在尝试根据选择哪个项目来更改我的自定义旋转器所选项目的颜色。
如果选择第一个元素,我想为文本视图设置灰色,因为我将第一个项目用作提示消息,其余项目必须是黑色的。
当我尝试该应用程序并第一次加载片段时,它以正确的方式工作,但是当我使用导航按钮转到另一个片段时,如果我再次切换到第一个片段,则setColor不是工作时,文本视图总是以黑色出现。
这是我用来更改片段中颜色的代码,
sexoSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View v, int position, long id) {
if (v == null)
{
LayoutInflater vi = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = vi.inflate(R.layout.item_gender, null);
}
iSexoSelected = position;
switch (position) {
case 0:
((TextView) v.findViewById(R.id.genderText)).setTextColor(getResources().getColor(R.color.gris_hint_fuente));
break;
case 1:
((TextView) v.findViewById(R.id.genderText)).setTextColor(getResources().getColor(R.color.black));
sexoSeleccion = "Femenino";
break;
case 2:
((TextView) v.findViewById(R.id.genderText)).setTextColor(getResources().getColor(R.color.black));
sexoSeleccion = "Masculino";
break;
}
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
我不知道为什么第二次加载片段的微调器颜色没有改变,有什么想法吗?
事先感谢您的所有帮助。
I'm trying to change the color for my Custom Spinner selected item depending on which item is selected.
if I select the first element i want to set a grey color for the TextView because I'm using the first item as a hint message and the rest of items must be black.
when I'm trying the app and i load the fragment for the first time, it works in the right way, but when i used the navigation buttons to go to another fragment, if i switch again to the first fragment, the SetColor is not working, the Textview always appear with the text in black.
here is the code that i'm using to change the color in my fragment
sexoSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View v, int position, long id) {
if (v == null)
{
LayoutInflater vi = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = vi.inflate(R.layout.item_gender, null);
}
iSexoSelected = position;
switch (position) {
case 0:
((TextView) v.findViewById(R.id.genderText)).setTextColor(getResources().getColor(R.color.gris_hint_fuente));
break;
case 1:
((TextView) v.findViewById(R.id.genderText)).setTextColor(getResources().getColor(R.color.black));
sexoSeleccion = "Femenino";
break;
case 2:
((TextView) v.findViewById(R.id.genderText)).setTextColor(getResources().getColor(R.color.black));
sexoSeleccion = "Masculino";
break;
}
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
i don't know why the second time i load the fragment the color for the spinner is not changing, any ideas ?
thanks in advance for all the help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论