gpt4 book ai didi

android - 单击后图标消失

转载 作者:行者123 更新时间:2023-11-29 15:35:11 29 4
gpt4 key购买 nike

我有一个可折叠的工具栏布局和一个 FAB。我在单击时动态更改 FAB 图标。它运作良好。但是当工具栏折叠并再次展开时。单击 FAB 会使图标消失。当我收起再展开时,图标出现了,而且图标变了!

布局.xml

<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">

<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="@dimen/app_bar_height"
android:fitsSystemWindows="true"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

<android.support.design.widget.CollapsingToolbarLayout
app:expandedTitleMarginStart="16dp"
android:id="@+id/collapsing_toolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
app:collapsedTitleTextAppearance="@style/AppTheme.ToolbarTitleCollapsed"
app:expandedTitleTextAppearance="@style/AppTheme.ToolbarTitle"
app:contentScrim="?attr/colorPrimary"
app:layout_scrollFlags="scroll|exitUntilCollapsed|snap">

<ImageView
android:id="@+id/cover"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:scaleType="centerCrop"
app:layout_collapseMode="parallax" />

<View
android:layout_width="match_parent"
android:layout_height="160dp"
android:layout_gravity="bottom"
android:background="@drawable/scrim" />

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

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

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

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

<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="true"
android:focusable="true"
android:src="@drawable/ic_favorite_black_24dp"
app:fabSize="normal"
android:layout_margin="16dp"
app:layout_anchor="@+id/appbar"
app:layout_anchorGravity="bottom|right|end" />

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

用于切换 FAB 图标的 Java 代码

final FloatingActionButton fab = findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (isSelected) {
fab.setImageDrawable(ContextCompat.getDrawable(MyActivity.this,R.drawable.ic_favorite_border_black_24dp));
fab.setColorFilter(Color.WHITE);
} else { fab.setImageDrawable(ContextCompat.getDrawable(MyActivity.this,R.drawable.ic_favorite_black_24dp));
fab.setColorFilter(Color.WHITE);
}
isSelected = !isSelected;
}
});

最佳答案

这是 Material 设计库 28.0 中的一个错误,已报告

https://issuetracker.google.com/issues/111316656

关于android - 单击后图标消失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52133846/

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