0

So I have a LinearLayout then inside is a ScrollView then inside is another RelativeLayout and finally inside is another LinearLayout with id mylinearlayout.

I want to create TextView's dynamically it works fine, but the text seems to be disabled like GRAY color. Although i didn't set any color.. Here's my code:

final LinearLayout linlayout = (LinearLayout) findViewById(R.id.mylinearlayout);
final TextView tv = new TextView(getApplicationContext());                          
tv.setTextSize(20);
tv.isEnabled();
tv.setGravity(Gravity.CENTER);
if(orderstatus.equals("Pending")) {
    tv.setText("OrderID: "+orderid + "\n"+"OrderDate: " + orderdate + "\n"  +"OrderStatus: "+orderstatus + " \n\n");
    tv.setId(i + 5);
    linlayout.addView(tv);
}
GIGAMOLE
  • 1,274
  • 1
  • 11
  • 17
Duckbenok
  • 95
  • 1
  • 2
  • 9

3 Answers3

0

You doing well, but miss one moment. When you add view into layout, view automaticly sets color from current system styles. If you need to change color of your text, do this:

tv.setTextColor(YOUR_COLOR);
GIGAMOLE
  • 1,274
  • 1
  • 11
  • 17
0

Use this code

linlayout = (LinearLayout) findViewById(R.id.mylinearlayout);
TextView tv = new TextView(getApplicationContext());
tv.setTextSize(20);
tv.isEnabled();
tv.setGravity(Gravity.CENTER);
if(orderstatus.equals("Pending"))
{
tv.setText("OrderID: "+orderid + "\n"+"OrderDate: " + orderdate + "\n"  +"OrderStatus: "+orderstatus + " \n\n");
tv.setId(i + 5);
tv.setTextColor(Color.BLACK);
linlayout.addView(tv);
}
Kadir altınok
  • 230
  • 2
  • 5
0

Your TextView text may grey because it's using the system Theme rather than your Activity's. You could try passing this instead of getApplicationContext() in your TextView() constructor. This is true for Toast objects, for example, and may also apply to widgets.

Community
  • 1
  • 1
PPartisan
  • 8,173
  • 4
  • 29
  • 48
  • thanks for the reply but when I use 'this' i get undefined error and when i use getApplicationContext(), R.style.AppTheme i also get error – Duckbenok Feb 02 '16 at 18:29