但是我从来没有像上面那样得到动作栏,这是我的布局:
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.AppBarLayout
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:fitsSystemWindows="true">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/collapsing_toolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_scrollFlags="scroll|exitUntilCollapsed"
app:contentScrim="?attr/colorPrimary"
android:fitsSystemWindows="true"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<android.support.v4.view.ViewPager
android:id="@+id/galleryPager"
android:layout_width="match_parent"
android:layout_height="250dp"
app:layout_collapseMode="parallax"
/>
<View
android:layout_width="match_parent"
android:layout_height="250dp"
android:background="@drawable/gallery_pager_overlay"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="1/8"
android:id="@+id/tvPicNum"
android:background="@drawable/background_viewpager_bubble"
android:textColorLink="@color/white"
android:layout_marginRight="16dp"
android:layout_marginEnd="16dp"
android:layout_alignBottom="@+id/galleryPager"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="false"
android:layout_marginBottom="40dp" />
</RelativeLayout>
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
app:layout_collapseMode="pin" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="@+id/tbTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="test this title"
android:textColor="@color/white"
android:textSize="14sp"
android:textStyle="bold" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="12dp"
android:scaleType="fitCenter"
android:adjustViewBounds="true"
android:src="@drawable/l5_stars"/>
</LinearLayout>
</android.support.v7.widget.Toolbar>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.NestedScrollView
android:id="@+id/scroll"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
>
<include layout="@layout/content_product_details" />
</android.support.v4.widget.NestedScrollView>
这是我的活动代码:
public class ProductDetailsActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_hotel_details);
ButterKnife.inject(this);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowHomeEnabled(true);
product = (Product)getIntent().getSerializableExtra("selectedProduct");
getSupportActionBar().setTitle(product.getTitle());
new getProductGallery().execute();
}
所以,请帮助正确的方法
由于