Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set Custom ActionBar to fixed top position inside ScrollView layout?

How do I set this action bar in a way even when scroll the long data screen it keeps visible on the top of the screen?

toolbar.xml:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:orientation="vertical" >

Guys please see my update: I tried everything but it seems that next component after actionBar is not being set after actionBar but behind it:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:background="@drawable/background_telas"
android:orientation="vertical" >

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

<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <ScrollView
        android:id="@+id/scrollView"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:fillViewport="true" >

        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="match_parent"
            android:orientation="vertical" >

            <TextView
                android:id="@+id/textView1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="TextView" />
        </LinearLayout>
    </ScrollView>
</LinearLayout>

enter image description here

<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/actionBar"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:background="@color/actionBarBackgroundColor"
    app:contentInsetEnd="0dp"
    app:contentInsetStart="0dp" >
</android.support.v7.widget.Toolbar>

<View
    android:layout_width="match_parent"
    android:layout_height="1dp"
    android:background="#A0A09F" />

Project (eclipse): Project in eclipse IDE

Screen stopped: Screen stopped showing acationbar on top

Screen scrolled up: Screen scrolled up showing the actionbar going up with other data

Java:

    Toolbar actionBar = (Toolbar) findViewById(R.id.actionBar);
    actionBar.setTitle("ProTaxi Passageiro");
    actionBar.setSubtitle("Cadastro");
    actionBar.setTitleTextColor(Color.parseColor("#846A1A"));
    setSupportActionBar(actionBar);
like image 886
Francisco Souza Avatar asked Dec 07 '25 09:12

Francisco Souza


2 Answers

If you don't want the Toolbar to scroll with the content, then you have to put it outside the ScrollView.

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

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

    <ScollView
        ...>

        you content here..

    </ScollView>

</LinearLayout>
like image 78
Floern Avatar answered Dec 09 '25 22:12

Floern


You can also set the layout_scrollFlags to enterAlways to get rid of the toolbar scrolling.

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="?attr/colorPrimary"
        app:layout_scrollFlags="enterAlways"
        app:popupTheme="@style/AppTheme.PopupOverlay">

    </android.support.v7.widget.Toolbar>
like image 24
codemoonger Avatar answered Dec 09 '25 21:12

codemoonger



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!