1

The default color of the Toast on the Kindle Fire is black text on a white background. I followed the instructions in this answer to try to set the text color to white and background color to black, but after these changes, there's still white showing behind the background so it looks like white text on a black background on a white background. Is there some other field I need to set the get the entire background black? Here's my code:

  Context context = ctx.getApplicationContext();
  CharSequence text = "Toasty text...";
  int duration = Toast.LENGTH_SHORT;

  Toast toast = Toast.makeText(context, text, duration);
  TextView v = (TextView) toast.getView().findViewById(android.R.id.message);
  v.setTextColor(Color.WHITE);
  v.setBackgroundColor(Color.BLACK);
  toast.show();

edit: I ended up doing a combination of CommonsWare's answer and this link to create the default toast and set the color.

Community
  • 1
  • 1
Waynn Lue
  • 11,344
  • 8
  • 51
  • 76

2 Answers2

3

Instead of using the static makeText() method, you could try using the regular constructor and then using setView() with your own custom layout for the Toast.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
1

CommonsWare is right for the ultimate control over the toast styling. But if you want to continue down the path you're headed, try:

toast.getView().setBackgroundDrawable(R.drawable.toast);

as you can see that the TextView is inside a LinearLayout that has a background drawable set on it. You need to change the background of the LinearLayout, not the TextView contained within.

For drawable resource (drawable/toast.xml), something like this:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
  <gradient android:startColor="#000000" android:centerColor="#202020" android:endColor="#000000" android:angle="90" />
  <stroke android:width="1dp" android:color="#808080" />
  <corners android:radius="8dp" />
</shape>

but you're really better off doing a custom layout per CommonsWare ...

CSmith
  • 13,318
  • 3
  • 39
  • 42