Toast text out of alignment

Asked

Viewed 336 times

0

I am working on a small project for the college and came across this when using a Toast: Toast Bizarro

I have no idea what made Toast look like this. Has anyone experienced a similar problem?

Edition: This is the code I’m using to create Toast:

Toast.makeText(Singleton.getInstance().getContext(), "Nota criada com sucesso!", Toast.LENGTH_SHORT).show();

I noticed that the error appeared after I installed the Systembartint library. Before using it, I had tried to get the same result using only XML aquives, but I was not satisfied. Can anything in it be influencing? This is mine styles.xml current:

<resources>

    <style name="AppTheme" parent="android:Theme.Holo.Light.DarkActionBar">
        <item name="android:actionBarStyle">@style/Notas.ActionBar</item>
        <item name="android:actionBarWidgetTheme">@style/Notas.ActionBar.OverflowMenu</item>
        <item name="android:fitsSystemWindows">true</item>
        <item name="android:clipToPadding">true</item>
        <item name="android:windowTranslucentStatus">true</item>
    </style>

    <style name="Notas.ActionBar" parent="@android:style/Widget.Holo.ActionBar">
        <item name="android:background">@color/roxo</item>
        <item name="android:titleTextStyle">@style/Notas.ActionBar.TitleTextStyle</item>
    </style>

    <style name="Notas.ActionBar.TitleTextStyle" parent="@android:style/TextAppearance.Holo.Widget.ActionBar.Title">
        <item name="android:textColor">@color/branco</item>
    </style>

    <style name="Notas.ActionBar.OverflowMenu" parent="android:Theme.Holo.Light">
        <item name="android:popupMenuStyle">@android:style/Widget.Holo.Light.PopupMenu</item>
        <item name="android:dropDownListViewStyle">
            @android:style/Widget.Holo.Light.ListView.DropDown
        </item>
    </style>
</resources>
  • Could you include the code? Is it not a line break that forces the text to have two lines? Could you test a trim in String?

  • @Wakim, I edited my question. I’m going to test Trim now. EDIT: the trim did not solve the problem.

  • Looking at the code there is no error. The trim will not help. Must be some style that is influencing in Toast, have to check the style of it. I do not recommend putting the fitSystemWindows and the clipToPadding in the AppTheme, can interfere in a lot of things. I usually put in each View layout root, but it can be laborious. Try doing the following: remove these two attributes to see if they are causing trouble in Toast.

1 answer

2


The problem is that the attribute android:fitsSystemWindows is specific to declarations of View's in xml layout, not for themes.

If you want to keep the theme with this attribute, a "workaround" would use the getApplicationContext() or getApplication(), as a context for the makeText. Thus:

// Se estiver dentro de uma Activity
Toast.makeText(getApplicationContext(), "Nota criada com sucesso!", Toast.LENGTH_SHORT).show();

// ou

Toast.makeText(getApplication(), "Nota criada com sucesso!", Toast.LENGTH_SHORT).show();

The ideal is to move the attribute android:fitsSystemWindows for each View which is the root of your layouts.

More information: Android AOSP Issue 63653.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.