noties / Scrollable

Android scrollable tabs
Apache License 2.0
1.24k stars 229 forks source link

How to add Toolbar in xml ? #9

Closed leelei closed 9 years ago

leelei commented 9 years ago

if my app use theme

<style name="AppTheme.Base" parent="Theme.AppCompat.Light.NoActionBar">

how to make sticky toolbar in xml ?

xu6148152 commented 9 years ago

are you kiding us...

leelei commented 9 years ago

i need this effect needed

if use

<style name="AppTheme.Base" parent="Theme.AppCompat">

it can work ,but i do not want use like that, i use

<style name="AppTheme.Base" parent="Theme.AppCompat.Light.NoActionBar">

but it does not work well

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:psts="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
  <ru.noties.scrollable.ScrollableLayout
      xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:app="http://schemas.android.com/apk/res-auto"
      xmlns:psts="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:id="@+id/scrollable_layout"
      app:scrollable_maxScroll="@dimen/user_profile_cover">

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

      <RelativeLayout
          xmlns:android="http://schemas.android.com/apk/res/android"
          xmlns:tools="http://schemas.android.com/tools"
          android:id="@+id/layout_profile_header"
          android:layout_width="match_parent"
          android:layout_height="@dimen/user_profile_cover"
          >

        <ImageView
            android:id="@+id/imageView_user_profile_cover"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_above="@+id/textView_user_screenname"
            android:scaleType="centerCrop"
            android:src="@color/primary"
            />

        <include
            android:id="@+id/imageView_portrait"
            android:layout_width="@dimen/avatar_large_size"
            android:layout_height="@dimen/avatar_large_size"
            android:layout_centerHorizontal="true"
            android:layout_marginTop="88dp"
            layout="@layout/layout_avatar"
            />

        <TextView
            android:id="@+id/textView_userverified_reason"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@id/imageView_portrait"
            android:layout_centerHorizontal="true"
            android:layout_marginTop="@dimen/spacing_normal"
            android:layout_marginLeft="40dp"
            android:layout_marginRight="@dimen/spacing_huge"
            android:layout_marginBottom="@dimen/spacing_small"
            android:textSize="16sp"
            android:singleLine="true"
            android:marqueeRepeatLimit="marquee_forever"
            android:ellipsize="marquee"
            style="@style/TextViewBody1"
            tools:text="马薇薇不算是昵马薇薇不马薇薇不算是昵马薇薇不马薇薇不算是昵马薇薇不马薇薇不算是昵马薇薇薇不算是昵马薇薇不马薇薇不算是昵马薇薇不马薇薇不算是昵马薇不算是昵马薇薇不马薇薇不算是昵马薇薇不马薇薇不算是昵马薇薇薇不算是昵马薇薇不马薇薇不算是昵马薇薇不马薇薇不算是昵马薇薇薇不算是昵马薇薇不马薇薇不算是昵马薇薇不马薇薇不算是昵马薇薇薇不算是昵马薇薇不马薇薇不算是昵马薇薇不马薇薇不算是昵马薇薇薇不算是昵马薇薇不马薇薇不算是昵马薇薇不马薇薇不算是昵马薇薇薇不算是昵马薇薇不马薇薇不算是昵马薇薇不马薇薇不算是昵马薇薇薇不算是昵马薇薇不马薇薇不算是昵马薇薇不马薇薇不算是昵马薇薇薇不算是昵马薇薇不马薇薇不算是昵马薇薇不马薇薇不算是昵马薇薇薇薇不"
            />

        <TextView
            android:id="@+id/textView_user_screenname"
            android:layout_width="match_parent"
            android:layout_height="40dp"
            android:layout_alignParentBottom="true"
            android:layout_centerHorizontal="true"
            android:paddingLeft="@dimen/spacing_large"
            android:paddingRight="@dimen/spacing_large"
            android:singleLine="true"
            android:ellipsize="marquee"
            android:gravity="center_vertical"
            style="@style/TextViewSubhead"
            android:textSize="18sp"
            android:textColor="@color/white"
            tools:text="马薇薇不算是昵称吧马薇薇不算"
            android:background="@color/white"
            />
      </RelativeLayout>

      <com.astuetz.PagerSlidingTabStrip
          android:id="@+id/tabs"
          android:layout_below="@id/toolbar"
          android:layout_width="match_parent"
          android:layout_height="@dimen/tab_strip_height"
          android:background="@color/white"
          psts:pstsShouldExpand="true"
          psts:pstsIndicatorColor="@color/white"
          android:textColor="@color/white"
          psts:pstsTextColorSelected="@color/white"
          />

      <ImageView
          android:id="@+id/fab_button"
          android:layout_width="@dimen/fab_size"
          android:layout_height="@dimen/fab_size"
          android:layout_marginTop="-116dp"
          android:background="@drawable/fab_button_teal"
          android:elevation="@dimen/elevation_normal"
          android:scaleType="centerInside"
          android:visibility="visible"
          android:layout_gravity="right"
          android:layout_marginRight="@dimen/spacing_normal"
          />

    </LinearLayout>

    <android.support.v4.view.ViewPager
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginTop="@dimen/tab_strip_height"
        android:id="@+id/view_pager"/>

  </ru.noties.scrollable.ScrollableLayout>

  <android.support.v7.widget.Toolbar
      xmlns:android="http://schemas.android.com/apk/res/android"
      android:id="@+id/toolbar"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:background="@color/fab_material_deep_purple_900"
      />
</FrameLayout>

Image

noties commented 9 years ago

Hi! The reason is behind the theme you are using Theme.AppCompat.Light.NoActionBar. It obviously states that theme does not have an action bar (aka toolbar). Why won't you use simple Theme.AppCompat.Light?

noties commented 9 years ago

Plus, include Toobar into your header (it's the @+id/layout_profile_header ViewGroup) and implement your sticky behavior in ScrollableLayout.setOnScrollChangedListener(). Please refer to the sample app for the concrete implementation.

noties commented 9 years ago

ping Is your problem solved?