Why is the width of toast shorter than its content?

佐手、 提交于 2019-12-25 01:07:16

问题


I wrote an activity which contains a navigation drawer (a simple fragment with a ListView inside), and a model and an adapter for the ListView. There is an ImageView and a TextView in a single list item, as it's usually be in many apps. That's all I have done, and the rest codes of the activity and fragment's classes were all generated automatically by Android Studio. Then when I used Toast.makeText in the activity, the result looks as this.

I've searched for this question and tried using Toast.makeText(this.getApplicationContext(), ...) instead of Toast.makeText(this, ...), and it worked. I'm wondering why would this happen and how should I solved this problem correctly?


回答1:


In the official documentation it says that a typical Toast looks like this:

Context context = getApplicationContext();
Toast toast = Toast.makeText(context, text, duration);

I imagine it is because depending on the class you have, the context varies because not all context instances are created equal.

More info also here:



来源:https://stackoverflow.com/questions/24475333/why-is-the-width-of-toast-shorter-than-its-content

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!