F. Alvarado
F. Alvarado

Reputation: 43

Button BackgroundColor disables the LinearLayout BackgroundColor

What can I do so that the android:background color of the Button doesn’t disable the LinearLayout android:background color? It’s when creating Buttons dynamically. Here is my code:

for (int i = 0; i < myList.size(); i++) {
        LinearLayout ll = (LinearLayout) findViewById(R.id.layout1);

        ll.setBackgroundColor(Color.parseColor("#FFFFFF"));  // WHITE
        LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
        Button myButton = new Button(this);
        myButton.setText(myList.get(i));

        myButton.setBackgroundColor(getResources().getColor(R.color.naranja)); // ORANGE

        ll.addView(myButton, lp);
        myButton.setId(i);
        myButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) { ………

Upvotes: 0

Views: 36

Answers (1)

Mikerizzo
Mikerizzo

Reputation: 601

It's not disabling the background color, you're drawing on top of it. If you change the LayoutParams to WRAP_CONTENT for width, you'll notice the background color is still white. Also, if you add some padding around the button you'll notice the same thing.

Upvotes: 2

Related Questions