Is there such a method call “getBackgroundColor”?

前端 未结 6 1783
旧巷少年郎
旧巷少年郎 2021-01-17 07:29

Is there such a method call \"getBackgroundColor\" in TextView? if I got 2 textViews: tv1 and tv2 in one LinearLayout. What I did:tv1.setBackgroundColor(Color.BLUE)

6条回答
  •  一向
    一向 (楼主)
    2021-01-17 08:10

    Setting a background color sets a Drawable with that specified color as the background, i.e. the following example will work just fine:

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.some_layout_name);
        TextView t1 = (TextView) findViewById(R.id.text1);
        TextView t2 = (TextView) findViewById(R.id.text2);
    
        t1.setBackgroundColor(Color.GREEN);
        t2.setBackgroundDrawable(t1.getBackground());
    }
    

提交回复
热议问题