如何解决突出的顶部应用栏无法正常工作
我想实现这个动画的折叠工具栏,即使在协调器布局中也无法正常工作。 请给我解决方案,以便我可以实施。
如果您还有其他需要,我已经将项目上传到了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中。
还有另一件事,为什么应用程序栏和底部导航栏位于协调器布局中的状态栏和软按钮后面
这就是我想要实现的目标
我遵循了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>