我已經嘗試了幾篇不同的文章,這裏有很多線索和教程,但我無法得到這個做任何事情。AppBarLayout拒絕做任何事
在我的代碼中,使用此佈局的活動是AppCompatActivity
。 我有AppCompatTheme.Light.NoActionBar
在我的活動內我設置setSupportActionBar()
到視圖R.id.toolbar
。
這是我的目標:http://imgur.com/Hl2Asb1.gif
// Dependencies
compile 'com.android.support:appcompat-v7:21.0.3'
compile 'com.android.support:cardview-v7:21.0.2'
compile 'com.android.support:recyclerview-v7:21.0.2'
compile 'com.android.support:appcompat-v7:21.0.3'
compile 'com.android.support:support-v13:21.0.3'
compile 'com.android.support:multidex:1.0.0'
compile 'com.android.support:design:22.2.0'
compile 'com.squareup.picasso:picasso:2.5.2'
compile 'com.jakewharton:butterknife:6.1.0'
這裏是我的xml:
<?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"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_scrollFlags="scroll|enterAlways"/>
</android.support.design.widget.AppBarLayout>
<android.support.v7.widget.RecyclerView
android:id="@+id/listview"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
</android.support.design.widget.CoordinatorLayout>
你有兩個'工具欄'的特殊原因嗎?你可以包含你的'build.gradle'文件的依賴關係嗎? – ianhanniballake
添加了我的依賴關係。我有兩個'工具欄',因爲我只是想要得到一些結果。 – Sherlock
我從xml中移除了第二個工具欄,以避免任何進一步的混淆。 – Sherlock