Javacadabra Javacadabra - 3 months ago 20x
Android Question

Toast background color being changed

I am working on a project and set the background of the application to white by doing the following:

<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
<item name="android:actionBarStyle">@style/MyActionBar</item>
<item name="android:actionBarSize">140dp</item>
<item name="android:background">#ffffff</item>

This works a charm however the problem is that the toast messages are now being displayed with a white background. The strange thing is that I integrated a splash screen into the project and when the user logs in the toast message is displayed normally.

It is really strange and would appreciate any help on the issue.

EDIT: ADDED SCREENSHOT SHOWING ISSUE. The screenshot is taken just as the initial toast (with unwanted effect) is fading out and the new one (with default) is fading in.

enter image description here


I resolved the issue. The reason for the change in the Toast background color was due to the way I was passing in the context of the View object it was contained inside.

The following line of code would cause the background color to change to the unwanted white color:

Toast.makeText(v.getContext(), "Checking login details...", Toast.LENGTH_SHORT).show();

This line of code would return the Toast to the default system style:

Toast.makeText(getApplicationContext(), "Checking login details...", Toast.LENGTH_SHORT).show();

I am not sure if there is a huge problem with fixing it like this as I am only learning. If anyone can see a problem please share. It seems to be working just fine though.