android - appBarLayout 在启动 Activity 时立即关闭

标签 android android-appbarlayout

我是安卓新手。我的一个 Activity 有一个 appbarLayout,问题是当开始该 Activity 时,app barLayout 立即关闭,我必须向下滚动才能再次打开它。我还将 app:expaned 设置为 true,但它对我不起作用。 我的代码:

<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/coordinatorLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/mygray">

<android.support.design.widget.AppBarLayout
    android:id="@+id/appBarLayout"
    android:layout_width="match_parent"
    android:layout_height="@dimen/appbar_h"
    app:expanded="true">

    <android.support.design.widget.CollapsingToolbarLayout
        android:id="@+id/collapsingToolbar"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:clipToPadding="true"
        android:foregroundGravity="bottom|right"
        android:foregroundTintMode="add"
        app:contentScrim="?attr/colorPrimary"
        app:layout_scrollFlags="scroll|exitUntilCollapsed"
        app:expandedTitleTextAppearance="@style/CustomToolbar">


        <com.github.mikephil.charting.charts.LineChart
            android:id="@+id/graph"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_below="@id/toolbar"
            android:background="@color/lime300"
            app:layout_collapseMode="parallax"></com.github.mikephil.charting.charts.LineChart>

        <android.support.v7.widget.Toolbar
            xmlns:android="http://schemas.android.com/apk/res/android"
            xmlns:app="http://schemas.android.com/apk/res-auto"
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:elevation="@dimen/elevation"
            app:layout_collapseMode="pin"
            app:theme="@style/Toolbar">
        </android.support.v7.widget.Toolbar>

        <TextView
            android:id="@+id/Mn"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom"
            android:layout_marginBottom="70dp"
            android:rotation="-90"
            android:text="بار محوری (KN)"
            android:textSize="@dimen/textsize_checkBox"
            android:textColor="@color/gray_heavy"/>
        <TextView
            android:id="@+id/Pn"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="@dimen/margin4"
            android:layout_marginStart="@dimen/margin4"
            android:layout_gravity="bottom"
            android:layout_marginBottom="@dimen/margin_columnAnalysis"
            android:text="لنگر خمشی (KN.m)"
            android:textSize="@dimen/textsize_checkBox"
            android:textColor="@color/gray_heavy"/>


    </android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>

<include layout="@layout/nested_scroll_view"/>

 </android.support.design.widget.CoordinatorLayout>

when start the activity

after scroll sown the appBarLyout

最佳答案

我有同样的问题。问题是 AppBarLayout 下的东西(在我的应用程序 fragment 中)将 AppBarLayout 向上推并关闭它,因为它的内容填充的空间超过了可见空间。但是我没有找到任何解决方案来防止这种情况......

当我隐藏 Fragment 的内容时,AppbarLayout 保持打开状态。

android:visibility="invisible"

更新:

我找到了解决方案:

您 View 中的一个元素正在获得焦点(可能是 EditText)。

为了防止我的应用程序崩溃,我必须将此语句放在 EditText 的 XML 中

android:focusable="false"

如果你想使用EditText,在onCreate中使用:

EditText text = findViewById(R.id.textEdit);
text.setFocusable(true);

更新 2:

另外,您可能需要恢复可编辑性:

text.setFocusableInTouchMode(true);

关于android - appBarLayout 在启动 Activity 时立即关闭,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45443070/

相关文章:

ANDROID:错误膨胀类 android.support.design.widget.AppBarLayout

android-appbarlayout - 迁移项目中的androidx appbarlayout问题

java - Android Touch UP 不工作

android - 为什么启动超过 2 个 AVD 仅在特定条件下有效

android - BottomSheetDialogFragment 在横向模式下不显示全高

android - AppBarLayout setExpanded速度慢

android - 底部应用栏导航图标不是垂直居中

android - AppBarLayout 禁用选定 View 上的拖动

android - 如何使用 deviceCheck 任务在远程设备上运行测试

Android GLSL 测试