12

I want to change the foreground color of a linearlayout. This is my code:layout.setForeground(new ColorDrawable(getResources().getColor(R.color.svbackclr))); But this call require minimum api level 23.So how to do the same on pre 23 api.

tahmidul hossain
  • 131
  • 1
  • 1
  • 8

3 Answers3

12

As @Gaurav suggested FrameLayout you can use the forground color by programatically in the following way

int color = R.color.black_trans_60;
frm.setForeground(new ColorDrawable(ContextCompat.getColor(mContext, color)));
Raju
  • 1,183
  • 3
  • 11
  • 19
9

I suggest to use FrameLayout In this you can use setForeground()

On any API level

Gaurav
  • 3,615
  • 2
  • 27
  • 50
4

This is a documentation bug . setForeground() existed on FrameLayout from API Level 1; it is only on View as of API Level 23.

So it best to extend FrameLayout

Real73
  • 490
  • 4
  • 13