java - 突出的顶部应用栏无法正常工作
问题描述
我想实现这个动画折叠工具栏,即使在协调器布局中也不能正常工作。请给我解决方案,以便我可以实施。
如果您需要其他任何内容,我已将项目上传到 github。
https://github.com/Mr-Akki-Jangir/MyNotes_android_application
这是具有此布局的 Activity。
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>
这是结果或我得到的结果,这个活动或课程只是一个实验课程,所以一旦我能够得到我想要的结果,我就会将它实现到主活动中。
还有一件事为什么应用程序栏和底部导航栏在协调器布局中的状态栏和软按钮后面
这就是我想要实现的目标
我已按照 Material.io 上的指南进行操作
你管教程https://www.youtube.com/watch?v=yzuSo4Bkh-k&t=781s
这个答案延迟了在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>
推荐阅读
- kotlin - 安装 Kotlin 独立编译器而不是使用 IntelliJ Kotlin 插件的利弊?
- python - 带有 ffprobe 流分析器的 if 语句
- javascript - 如何解决 Angular8 中的视图封装问题?
- pandas - 如何计算熊猫中值随时间的变化?
- c++ - 如何将文字转义转换为“真实”转义,以便“正确”打印它们?
- r - 使用分类数据而不是连接线创建线图
- javascript - 如何从祖先覆盖嵌套 Material UI 组件的样式?
- apache-kafka - 如何连接到内部 Kafka 集群
- r - 如何在 Rselenium R 中捕获动态 xpath id
- php - LeagueCSV:getRecords() 上的未定义索引