gpt4 book ai didi

android - 在 CollapsingToolbarLayout 后隐藏标题

转载 作者:太空宇宙 更新时间:2023-11-03 11:00:26 24 4
gpt4 key购买 nike

我有以下问题:我创建了一个 CollapsingToolbarLayout 并在标题下方添加了一个灰色的 TabLayout。

在 CollapsingToolbarLayout 之后/之后的屏幕:

问题:当它滑动时,我只想修复 TabLayout。滑动内容时如何去除或隐藏标题?

代码 x m l:

<android.support.design.widget.AppBarLayout
android:id="@+id/app_bar"
android:layout_width="match_parent"
android:layout_height="@dimen/app_bar_height"
android:fitsSystemWindows="true">

<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/collapsing"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
app:contentScrim="@android:color/transparent"
app:layout_scrollFlags="scroll|exitUntilCollapsed"
app:expandedTitleGravity="bottom"
app:expandedTitleMarginStart="48dp"
app:expandedTitleMarginEnd="64dp"
app:expandedTitleMarginBottom="70dp"
>
<ImageView
android:id="@+id/main.backdrop"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
android:fitsSystemWindows="true"
android:src="@drawable/backexemplo"
app:layout_collapseMode="parallax"
tools:ignore="ContentDescription"
/>

<android.support.v7.widget.Toolbar
android:id="@+id/toolbarPerfilEmpresa"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_collapseMode="parallax"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
/>

<android.support.design.widget.TabLayout
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:layout_gravity="bottom|end"
android:background="@color/colorPrimaryDark"
app:tabMode="fixed">

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

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

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

代码java:

public class PerfilEmpresaActivity extends AppCompatActivity {

private Toolbar mToolbar = null;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_perfil_empresa);
mToolbar = (Toolbar) findViewById(R.id.toolbarPerfilEmpresa);
// mToolbar.setLogo( R.drawable.paypal );
mToolbar.setTitle("NomeApp");

setSupportActionBar(mToolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);

坦克!

最佳答案

    mCollapsingToolbarLayout = view.findViewById(R.id.collapsing_toolbar);
mCollapsingToolbarLayout.setTitle("Title");
appBarLayout = view.findViewById(R.id.app_bar);
appBarLayout.addOnOffsetChangedListener(new AppBarLayout.OnOffsetChangedListener() {
boolean isShow = false;
int scrollRange = -1;

@Override
public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) {
if (scrollRange == -1) {
scrollRange = appBarLayout.getTotalScrollRange();
}
if (scrollRange + verticalOffset == 0) {
mCollapsingToolbarLayout.setTitle(" "); // Careful! There should be a space between double quote. Otherwise it won't work.
isShow = false;
} else if (!isShow) {
mCollapsingToolbarLayout.setTitle("Title");
isShow = true;
}
}
});

关于android - 在 CollapsingToolbarLayout 后隐藏标题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45226200/

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