答案 0 :(得分:1)
有点晚但我认为这可能有助于寻找解决方案的人,你可以简单地将文字颜色设置为透明。 只需将以下样式添加到styles.xml:
<style name="ToolBarTheme">
<item name="android:textColor">@android:color/transparent</item>
</style>
并将以下属性添加到您的CollapsingToolbarLayout:
app:expandedTitleTextAppearance="@style/ToolBarTheme"
答案 1 :(得分:1)
只需将此行添加到xml文件中的CollapsingToolbarLayout中:
app:titleEnabled="false"
答案 2 :(得分:0)
最好将它转换为正常活动(使用滚动视图作为孩子),从隐藏操作栏开始(使用下面的hide()调用(将其放在onCreate()中)。
然后将彩色backgroiund放在scrollview内的屏幕顶部。 最后,您可以通过编程方式在隐藏标题(和操作栏)之间切换,但在需要时通过添加水平滚动侦听器/观察器来显示标题背景(反之亦然)。
侦听器将根据用户向下滚动的距离切换操作栏和标题视图。
E.g:
在onStart()中添加观察者:
hsv.getViewTreeObserver().addOnScrollChangedListener(
new ViewTreeObserver.OnScrollChangedListener()
{ @Override public void onScrollChanged()
{
Log.i(TAG,"scroll:"+hsv.getScrollX());}});
// todo adjust scrollx value to decide on hide or show call:
if (hsv.getScrollX() > 100)
getActionBar().show();
mHeaderLayoutView.setVisibility(View.GONE);
else
getActionBar().hide();
mHeaderLayoutView.setVisibily(View.VISIBLE)
...
注意:hsv是HorizontalScrollView的工作原理。
注意,如果您正在使用支持库(例如,您的活动类扩展了AppCompatActivity),则代码将更改为:
getSupportActionBar().hide();
我不确定getScrollX是像素还是dp(你可以研究工作)。
希望这有帮助!
答案 3 :(得分:0)
$con = new mysqli("host","user","pass","db");
if ($mysqli->errno)
{
echo "Failed to connect to MySQL: " . $mysqli->error;
}
这必须是你的dimens.xml文件。如果您将app_bar_height缩小为120dp或关闭...文本将不可见。我不知道如何在崩溃后把它带回来
答案 4 :(得分:0)
这对我有用:
CollapsingToolbarLayout toolbarLayout = (CollapsingToolbarLayout)
findViewById(R.id.toolbar_layout);
toolbarLayout.setTitle(" ");
答案 5 :(得分:0)
您必须删除XML中的行android:theme="@style/AppTheme.AppBarOverlay"
。删除标题后,将转到后台。所以你可以隐藏活动的标题。例如,您可以放置一个占位符来隐藏它。
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<android.support.design.widget.AppBarLayout
android:id="@+id/app_bar"
android:layout_width="match_parent"
android:layout_height="220dp"
android:fitsSystemWindows="true"
>
<!--android:theme="@style/AppTheme.AppBarOverlay"-->
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/toolbar_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
app:contentScrim="?attr/colorPrimary"
app:layout_scrollFlags="scroll|exitUntilCollapsed"
app:toolbarId="@+id/toolbar">
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:scaleType="centerCrop"
app:layout_collapseMode="pin"
app:srcCompat="@drawable/place_holder" />
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginLeft="6dp"
android:layout_marginStart="6dp"
android:layout_marginTop="8dp"
android:src="@mipmap/next"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_collapseMode="pin"
app:popupTheme="@style/AppTheme.PopupOverlay"/>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<include layout="@layout/content_display_shop" />
</android.support.design.widget.CoordinatorLayout>
答案 6 :(得分:0)
您可以使用 supportActionBar 并使用 "" (string null) 更改标题
setSupportActionBar(findViewById(R.id.toolbar))
findViewById<CollapsingToolbarLayout>(R.id.toolbar_layout).title = title
supportActionBar!!.title=""
supportActionBar!!.setDisplayHomeAsUpEnabled(true)
或者您可以在 findViewById 中更改
findViewById<CollapsingToolbarLayout>(R.id.toolbar_layout).title = title
答案 7 :(得分:-1)
从onCreate()
initCollapsingToolbar();
定义方法
private void initCollapsingToolbar() {
final CollapsingToolbarLayout collapsingToolbar =
(CollapsingToolbarLayout) findViewById(R.id.toolbar_layout);
collapsingToolbar.setTitle(" ");
AppBarLayout appBarLayout = (AppBarLayout) findViewById(R.id.app_bar);
appBarLayout.setExpanded(true);
// hiding & showing the title when toolbar expanded & collapsed
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) {
collapsingToolbar.setTitle("Your app title");
isShow = true;
} else if (isShow) {
collapsingToolbar.setTitle(" ");
isShow = false;
}
}
});
}