gpt4 book ai didi

android - SnackBar 和 fitSystemWindows

转载 作者:IT老高 更新时间:2023-10-28 23:14:31 39 4
gpt4 key购买 nike

我有一个使用 fitSystemWindows 能够在导航栏和状态栏后面绘制背景的应用程序 - 不幸的是,SnackBar 似乎忽略了容器中的 fitSystemWindows=true。我将问题归结为这个最小的应用程序:

problem

风格:

<resources>

<style name="AppTheme" parent="Theme.AppCompat.Light">

<item name="android:windowBackground">@color/accent_material_dark</item>
<item name="android:fitsSystemWindows">false</item>

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

</resources>

布局:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"

android:fitsSystemWindows="true"
tools:context=".MainActivity">

<Button

android:id="@+id/button"
android:text="@string/hello_world"
android:layout_width="match_parent"
android:layout_height="match_parent"/>

</RelativeLayout>

Activity :

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
findViewById(R.id.button).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(final View v) {
Snackbar.make(v,"This Snackbar should fitSystemWindows",Snackbar.LENGTH_INDEFINITE).show();
}
});
}

}

有人知道一些解决方法吗?

我发布了最小的应用程序来显示这里的问题: https://github.com/ligi/SnackBarFitsSystemWindowProblem

最佳答案

Snackbar 将始终寻找一个 CoordinatorLayout 来锚定自己:当您没有时,它使用完整的内容 View (在您的情况下,包括状态栏下方的区域)- 添加一个具有 fitsSystemWindows=trueCoordinatorLayout 就可以了。

关于android - SnackBar 和 fitSystemWindows,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31492040/

39 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com