Android Runtime Layout Tutorial

后端 未结 4 1924
灰色年华
灰色年华 2020-11-29 05:04

Does anyone know how to perform or have a good reference for doing an activity layout at runtime in android?

Here is the code for my activity. I\'m sure I\'m just ne

4条回答
  •  刺人心
    刺人心 (楼主)
    2020-11-29 05:38

    I'm not sure if this question has been answered or not, but I just overcame this same issue today. Viet touched on the issue above but did not explicitly point out to check your color values. If you're coming from J2ME background like myself, you might be defining your color int values as 0xRRGGBB, so for full red J2ME would define it as 0xFF0000. However, doing so on Android will result in an int value of 0x00FF0000. Because Android uses the format of 0xAARRGGBB, a value of 0xFF0000 (J2ME) is actually (0x00FF0000) in Android this is full Red color that is COMPLETLY TRANSPARENT, so it's not seen on screen.

    I Noticed above in your code you're using question.setTextColor(R.color.green); This statement will assign the id value created in the R file, so it's probably a high number with some value as 0x7f050000 where the Alpha is set lower than FULL OPAQUE. Try your example with:

    question.setTextColor( getResources().getColor( R.color.green ) );
    

    This should set the text color to the value in R.color.green not the ID of R.color.green.

提交回复
热议问题