禁用工具栏在滚动时折叠
Disable toolbar collapsing on scrolling
我有一个带工具栏的 activity,当我滚动滚动视图时它会隐藏,但是,内容并不比 phone 屏幕大多少,所以我想禁用隐藏工具栏,因为它没有任何意义。我该怎么做?
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/svCreateAdvert"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<RelativeLayout
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="wrap_content"
android:background="@color/grey"
android:orientation="vertical"
tools:context=".CreateAdvert">
<LinearLayout
android:id="@+id/create_advert_container_toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<android.support.v7.widget.Toolbar
android:id="@+id/createAdvertToolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:popupTheme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"/>
</LinearLayout>
...
</RelativeLayout>
</ScrollView>
将工具栏放在滚动视图之外,滚动将不会影响工具栏。
您需要像这样在工具栏和滚动视图周围添加额外的线性布局。
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/create_advert_container_toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<android.support.v7.widget.Toolbar
android:id="@+id/createAdvertToolbar"
app:popupTheme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" />
<ScrollView
android:id="@+id/svCreateAdvert"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<RelativeLayout 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="wrap_content"
android:background="@color/grey"
android:orientation="vertical"
tools:context=".CreateAdvert">
</RelativeLayout>
</ScrollView>
</LinearLayout>
我有一个带工具栏的 activity,当我滚动滚动视图时它会隐藏,但是,内容并不比 phone 屏幕大多少,所以我想禁用隐藏工具栏,因为它没有任何意义。我该怎么做?
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/svCreateAdvert"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<RelativeLayout
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="wrap_content"
android:background="@color/grey"
android:orientation="vertical"
tools:context=".CreateAdvert">
<LinearLayout
android:id="@+id/create_advert_container_toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<android.support.v7.widget.Toolbar
android:id="@+id/createAdvertToolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:popupTheme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"/>
</LinearLayout>
...
</RelativeLayout>
</ScrollView>
将工具栏放在滚动视图之外,滚动将不会影响工具栏。
您需要像这样在工具栏和滚动视图周围添加额外的线性布局。
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/create_advert_container_toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<android.support.v7.widget.Toolbar
android:id="@+id/createAdvertToolbar"
app:popupTheme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" />
<ScrollView
android:id="@+id/svCreateAdvert"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<RelativeLayout 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="wrap_content"
android:background="@color/grey"
android:orientation="vertical"
tools:context=".CreateAdvert">
</RelativeLayout>
</ScrollView>
</LinearLayout>