0
Hey, guys, I’m having a little bit of a problem. I’m trying to change the color of a text inside a standard Listview android, however, it does not change. I tried changing the color in Layout, changed by code and nothing. Check my trial codes:
Modification via code:
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View view = inflater.inflate(R.layout.fragment_avisos, container, false);
TxtSemAviso = view.findViewById(R.id.TxtSemAviso);
final ArrayList<String> avisos = preencherDados();
final ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>
(DashBoardActivity.context, android.R.layout.simple_list_item_1, avisos){
@SuppressLint("ResourceAsColor")
@Override
public View getView (int position, View convertView, ViewGroup parent) {
View view = super.getView(position, convertView, parent);
// Como o simple_list_item_1 retorna um TextView, esse cast pode ser feito sem problemas
((TextView) view).setTextColor(R.color.colorverde2);
return view;
}
};
Modification via XML:
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/text1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceListItemSmall"
android:gravity="center_vertical"
android:paddingStart="?android:attr/listPreferredItemPaddingStart"
android:paddingEnd="?android:attr/listPreferredItemPaddingEnd"
android:minHeight="?android:attr/listPreferredItemHeightSmall"
android:textColor="@color/colorverde2"/>
You want to change the color of just one listview item or all?
– Murillo Comino