Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setting background color #374

Open
neri4488 opened this issue Oct 30, 2018 · 2 comments
Open

Setting background color #374

neri4488 opened this issue Oct 30, 2018 · 2 comments

Comments

@neri4488
Copy link

When I set the background color like any other view i.e android:background="@color/white" , it does not show up.
How can you set background color??

@szirakim
Copy link

szirakim commented Nov 1, 2018

The init(Context c, AttributeSet a) {} function contains this part:

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
setBackground(null);
} else {
setBackgroundDrawable(null);
}

meaning this attribute is ignored as it is. A five minute solution is to copy the library to your project and remove this five lines. From that moment, you are good to go.

@szirakim
Copy link

szirakim commented Nov 1, 2018

A better advice:

  • use inheritance, use this class

This could prevent the library null out the background you specified, code:

public class MatEditText extends MaterialEditText {

public MatEditText(Context context) {
    super(context);
}

public MatEditText(Context context, AttributeSet attrs) {
    super(context, attrs);
}

public MatEditText(Context context, AttributeSet attrs, int style) {
    super(context, attrs, style);
}

@Override
public void setBackgroundDrawable(Drawable background) {
    if (background != null)
        super.setBackgroundDrawable(background);
}

@Override
public void setBackground(Drawable background) {
    if (background != null)
        super.setBackground(background);
}

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants