android toast doesn't fit text

后端 未结 2 733
一向
一向 2021-02-15 03:48

I am developing an application where I have to use numerous toasts.

I display these toasts by using:

Toast.makeText(context, \"Some medium-sized text\",          


        
2条回答
  •  无人及你
    2021-02-15 04:40

    Try inserting a carriage-return and line-feed where you want to split the text.

    These characters refer back to the old typewriter models. Carriage return was the cylinder moving back to the start and line feed was the cylinder rolling (feeding) by one line.

    In computing these are represented by two escaped characters (special codes that allow non-printable codes inside a string by prefixing them with a backslash \).

    • A carriage return is represented by \r
    • A line-feed is represented by \n (you can remember this as a new line).

    Some non-unix systems (e.g. Windows) require both, others (e.g Linux on which Android is based) only need the new line but it is generally safe to do both everywhere. The one thing that is essential is the order they are in. It must be \r\n

    To put this into your example:

    Toast.makeText(context, "First line of text\r\nSecond line of text", Toast.LENGTH_SHORT).show();
    

    In Android you should be able to reduce this to just the new line character \n as unix based systems are not so fussy:

    Toast.makeText(context, "First line of text\nSecond line of text", Toast.LENGTH_SHORT).show();
    

提交回复
热议问题