Android笔记:解决使用沉浸式状态栏后Toast不显示

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_25749749/article/details/81950941

近期发现个问题当你在API19以上定义沉浸式风格的UI时,可能会定义整个App的Theme为:

 <item name="android:windowTranslucentNavigation">true</item> 
 <item name="android:windowTranslucentStatus">true</item> 
 <item name="android:fitsSystemWindows">true</item>


这样的话Toast的文字便不会居中显示,而在背景框中靠上的位置。

随手搜一下,会得到如下答案:

  • 将fitsSystemWindows设置为false。
    (WTF,我要是能设置成false就不在AppTheme中指定为true了。)
  • 将Toast.makeText(context, msg, length)中第一个参数的context使用Application的Context而不是使用Activity的context。
    (结果是居中了,可是Toast的样式却也变了。)

解决方案

问题的原因在于将fitsSystemWindows用错了地方。fitsSystemWindows应该定义在View的Layout文件中,而不是定义在Theme里。



 

猜你喜欢

转载自blog.csdn.net/qq_25749749/article/details/81950941