Đây là mã.Thanh công cụ không hiển thị từ bên trong thanh công cụ thu gọn
<?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:id="@+id/main"
android:layout_height="match_parent"
android:layout_width="match_parent">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="100dp">
<android.support.design.widget.CollapsingToolbarLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_scrollFlags="scroll|enterAlways|exitUntilCollapsed">
<android.support.v7.widget.Toolbar
android:id="@+id/mytoolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:title="@string/app_name"
app:layout_collapseMode="pin"
app:theme="@style/ThemeOverlay.AppCompat.Light"/>
<android.support.design.widget.TabLayout
android:id="@+id/main_tablayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
app:layout_collapseMode="none"/>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<!--<android.support.v4.widget.NestedScrollView-->
<!--android:id="@+id/nestedscroll"-->
<!--android:layout_width="match_parent"-->
<!--android:layout_height="match_parent"-->
<!--android:fillViewport="true"-->
<!--android:scrollbars="horizontal"-->
<!--app:layout_behavior="@string/appbar_scrolling_view_behavior">-->
<android.support.v4.view.ViewPager
android:id="@+id/main_viewpager"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
<!--</android.support.v4.widget.NestedScrollView>-->
<android.support.design.widget.FloatingActionButton
android:id="@+id/main_fab"
android:layout_margin="16dp"
android:src="@android:drawable/ic_media_play"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_anchor="@id/main_viewpager"
app:layout_anchorGravity="bottom|end"/>
</android.support.design.widget.CoordinatorLayout>
Vấn đề:
1) Thanh công cụ là không nhìn thấy được.
2) Thanh công cụ thu gọn không hề sụp đổ. [Solved]
3) Viewpager và FAB cũng không hiển thị nếu được đặt bên trong nestedScrollView. [Solved]
thêm chi tiết:
Layout cho mảnh ViewPager có LinearLayout như là người chủ và bên trong đó có một recyclerview.
Mọi thứ dường như không sao theo mã. Không thể hiểu những gì còn thiếu. Một lời giải thích tốt về cách bố trí phối hợp và thu gọn thanh công cụ làm việc cùng nhau cũng sẽ thực sự giúp đỡ.
đã tìm hình thứ 2 và thứ 3. Cái đầu tiên không hoạt động ngay cả sau khi thực hiện điều này 'Thanh công cụ Thanh công cụ = (Thanh công cụ) findViewById (R.id.toolbar); setSupportActionBar (thanh công cụ); ' –
@DarshanMiskin Tôi đã cập nhật câu trả lời của mình. Bạn đã quên đặt chiều cao Thanh công cụ mặc định - 'wrap_content' có thể nằm trong trường hợp đó bằng 0. Thuộc tính 'actionBarSize' đặt kích thước Thanh công cụ chuẩn của Android. – piotrek1543
đã thử nó .. vẫn không có gì .. –