突出的顶部应用栏无法正常工作

如何解决突出的顶部应用栏无法正常工作

我想实现这个动画的折叠工具栏,即使在协调器布局中也无法正常工作。 请给我解决方案,以便我可以实施。

如果您还有其他需要,我已经将项目上传到了github。

https://github.com/Mr-Akki-Jangir/MyNotes_android_application

这里是具有这种布局的活动。

package com.example.mynotes;

import android.net.Uri;
import android.os.Bundle;
import android.widget.FrameLayout;
import android.widget.TextView;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.FragmentTransaction;

import com.example.mynotes.Fragments.AllNotesFragment;
import com.google.android.gms.auth.api.signin.GoogleSignInClient;
import com.google.android.gms.common.SignInButton;
import com.google.android.material.button.MaterialButton;

import de.hdodenhof.circleimageview.CircleImageView;

public class GoogleSignIn extends AppCompatActivity {

    MaterialButton loginBtn,logoutBtn,btn_to_signup,goto_register;
    SignInButton GoogleLoginButton;
    TextView name,email;
    CircleImageView profilepPic;

    String GoogleName,GoogleEmail;
    Uri GooglePicUrl;

    FragmentTransaction fm;

    private GoogleSignInClient mGoogleSignInClient;

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.google_sign_in_layout);
}

这是活动的布局文件

<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:app="http://schemas.android.com/apk/res-auto">




    <com.google.android.material.appbar.AppBarLayout
        android:id="@+id/main_screen_topAppBar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:liftOnScroll="true"
        android:theme="@style/ThemeOverlay.MaterialComponents.ActionBar">

        <com.google.android.material.appbar.CollapsingToolbarLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:expandedTitleMarginStart="22dp"
            app:expandedTitleMarginEnd="28dp"
            app:expandedTitleGravity="bottom"
            app:expandedTitleTextAppearance="@style/TextAppearance.App.CollapsingToolbar.Expanded"
            app:collapsedTitleTextAppearance="@style/TextAppearance.App.CollapsingToolbar.Collapsed"
            app:layout_scrollFlags="scroll|exitUntilCollapsed"
            app:contentScrim="?attr/colorPrimary"
            app:toolbarId="@id/tool_bar">

            <com.google.android.material.appbar.MaterialToolbar
                android:id="@+id/tool_bar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                android:background="@color/white"
                app:menu="@menu/main_screen_top_app_bar_menu"
                app:title="@string/appbarTitle"
                app:navigationIcon="@drawable/navigation_menu_icon_downloaded"
                style="@style/Widget.MaterialComponents.Toolbar.Primary"
                android:elevation="0dp"
                app:layout_collapseMode="pin" />

        </com.google.android.material.appbar.CollapsingToolbarLayout>


    </com.google.android.material.appbar.AppBarLayout>

    <androidx.core.widget.NestedScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="com.google.android.material.appbar.AppBarLayout$ScrollingViewBehavior">


        <androidx.constraintlayout.widget.ConstraintLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <ImageView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:src="@drawable/glacier_mountain"
                app:layout_constraintTop_toTopOf="parent"
                app:layout_constraintLeft_toLeftOf="parent"/>



        </androidx.constraintlayout.widget.ConstraintLayout>


    </androidx.core.widget.NestedScrollView>

    <com.google.android.material.bottomnavigation.BottomNavigationView
        android:id="@+id/bottom_nav_drawer"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/bottom_nav_bg"
        android:paddingBottom="5dp"
        app:itemIconSize="24dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:itemIconTint="@drawable/icon_tint"
        app:itemTextColor="@drawable/icon_tint"
        app:menu="@menu/bottom_nav_menu"
        android:layout_gravity="bottom"/>

</androidx.coordinatorlayout.widget.CoordinatorLayout>

这是结果或我得到的结果,并且此活动或课程只是实验班,因此一旦我能够获得想要的结果,则将其实施到Main Activity中。

还有另一件事,为什么应用程序栏和底部导航栏位于协调器布局中的状态栏和软按钮后面

enter image description here

这就是我想要实现的目标

enter image description here

我遵循了Material.io上的指南

您的教程https://www.youtube.com/watch?v=yzuSo4Bkh-k&t=781s

此答案Delayed scrolling behavior in an app with scrolling "prominent top app bar" in Android

但是其中没有一个工作,请任何人给我正确的布局文件,以便我可以完成我的项目。

解决方法

经过大量研究,我自己找到了解决方案。 在我的AppTheme中,由于三个重要属性,顶部应用程序栏在状态栏后面重叠的主要原因是正确的。

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

所以我把它们改成了

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

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其他元素将获得点击?
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。)
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?
Java在半透明框架/面板/组件上重新绘画。
Java“ Class.forName()”和“ Class.forName()。newInstance()”之间有什么区别?
在此环境中不提供编译器。也许是在JRE而不是JDK上运行?
Java用相同的方法在一个类中实现两个接口。哪种接口方法被覆盖?
Java 什么是Runtime.getRuntime()。totalMemory()和freeMemory()?
java.library.path中的java.lang.UnsatisfiedLinkError否*****。dll
JavaFX“位置是必需的。” 即使在同一包装中
Java 导入两个具有相同名称的类。怎么处理?
Java 是否应该在HttpServletResponse.getOutputStream()/。getWriter()上调用.close()?
Java RegEx元字符(。)和普通点?