The background color of the list becomes white in the scroll when using android.support.v4.app.ListFragment;

I ran into a serious problem. I am trying to change the background color of a (transparent) list while scrolling, but cannot do this. I tried changing this by xml listView as well as by code. but in both conditions the background of the list becomes white . I am using android.support.v4.app.ListFragment; and FragmentPagerAdapter.

I want to change the scroll color of a list. I use the following code for this.

public static class ArrayListFragment extends ListFragment { int mNum; /** * Create a new instance of CountingFragment, providing "num" * as an argument. */ static ArrayListFragment newInstance(int num) { ArrayListFragment f = new ArrayListFragment(); // Supply num input as an argument. Bundle args = new Bundle(); args.putInt("num", num); f.setArguments(args); return f; } /** * When creating, retrieve this instance number from its arguments. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mNum = getArguments() != null ? getArguments().getInt("num") : 1; } /** * The Fragment UI is just a simple text view showing its * instance number. */ @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View v = inflater.inflate(R.layout.fragment_pager_list, container, false); //v.setBackgroundResource(R.drawable.background); View tv = v.findViewById(R.id.text); ((TextView)tv).setText(frameName()); return v; } // @Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); setListAdapter(new ArrayAdapter<String>(getActivity(), android.R.layout.simple_list_item_checked, RishavArraylist() )); } 

Please tell me how can I change the background of the scrollable list at runtime? Thanks.

+7
source share
2 answers

Take a look at this blog post from Google, in particular the XML part related to;

  android:cacheColorHint="#00000000" 
+14
source

We have many options for this problem, you can set the background as transparent using programming, for example

 yourlistview.setCacheColorHint(Color.TRANSPARENT); 

or through xml

 android:cacheColorHint="@android:color/transparent" 
+3
source

All Articles