Set border and background color of textView

后端 未结 2 448
难免孤独
难免孤独 2020-12-30 05:21

I have a TextView defined in XML and i would like to set background color AND border to it. Problem i have is that in XML i already use android:background for s

2条回答
  •  情深已故
    2020-12-30 06:05

    Via Java:

    TextView c1 = new TextView(activity);
    c1.setTextColor(getResources().getColor(R.color.solid_red));
    c1.setText("My Text");    
    
    TextView test = (TextView) view.findViewById(R.id.textView2);
    test.setBackgroundResource(R.color.holo_green_light);
    

    Via XML:

     
    

    This is the API page about this topic: http://developer.android.com/guide/topics/resources/accessing-resources.html#ResourcesFromXml

提交回复
热议问题