set background color: Android

前端 未结 4 548
旧时难觅i
旧时难觅i 2020-12-29 02:22

How Do I set the background color of my android app. When I try:

LinearLayout li=(LinearLayout)findViewById(R.id.myLayout);
li.setBackgroundColor(Color.parse         


        
4条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-29 02:54

    This question is a old one but it can help for others too.

    Try this :

        li.setBackgroundColor(getResources().getColor(R.color.blue));
    
        or
    
        li.setBackgroundColor(getResources().getColor(android.R.color.red));
    
        or
    
        li.setBackgroundColor(Color.rgb(226, 11, 11));
    
    
        or
        li.setBackgroundColor(Color.RED)
    

提交回复
热议问题